Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP add support for EIP1559 and CIP42 to ContractKit (wallet-base) #10474

Closed
wants to merge 225 commits into from
Closed
Show file tree
Hide file tree
Changes from 224 commits
Commits
Show all changes
225 commits
Select commit Hold shift + click to select a range
3e3ccc3
Node 18
dckesler Sep 19, 2022
f834eb0
update truffle-ganache-ethereumjs dependencies
soloseng Feb 25, 2023
4925a77
fix build errors
soloseng Feb 25, 2023
4bfa245
split migration into JS & TS dir
soloseng Feb 25, 2023
855a0f2
build with latest node 18.14
soloseng Mar 1, 2023
bea2954
-- ganache.server promise wrapper
soloseng Mar 1, 2023
6964637
ignore migrations_ts js files
soloseng Mar 1, 2023
98408bd
sync with master
soloseng Mar 2, 2023
bb768d8
added resolutions
soloseng Mar 3, 2023
b3bbcad
Merge branch 'soloseng/syncing-with-master' into soloseng/ganache-upg…
soloseng Mar 4, 2023
91dca89
remove lib
soloseng Mar 4, 2023
cde57f8
removed leftover old dependencies
soloseng Mar 7, 2023
7955d93
fixed revert assersion error message
soloseng Mar 9, 2023
493fca7
WIP notes
soloseng Mar 17, 2023
f0addc4
WIP todos
soloseng Mar 17, 2023
0a6cfa9
updated web3 & ethereumjs in utils & protocol
soloseng Mar 28, 2023
861d5c3
++ ethereum-cryptography dependency
soloseng Mar 30, 2023
53adec3
Merge branch 'soloseng/fixing-test' into soloseng/update-web3-ethereumjs
soloseng Apr 1, 2023
ff4e7e8
Merge branch 'soloseng/fixing-gas-price'
soloseng Apr 1, 2023
8de0e9d
timeout fix
soloseng Apr 5, 2023
4be4285
-- comments
soloseng Apr 5, 2023
686659a
Fixed overflow test
soloseng Apr 5, 2023
a8c3288
Merge branch 'soloseng/ast-version_fix'
soloseng Apr 6, 2023
4b46543
Merge branch 'soloseng/fixing-test' into soloseng/update-web3-ethereumjs
soloseng Apr 6, 2023
e50fe29
using istanbul hardfork
soloseng Apr 18, 2023
00bb385
Merge branch 'soloseng/update-web3-ethereumjs' into soloseng/ganache-…
soloseng Apr 18, 2023
2c31969
Merge branch 'master' into soloseng/sync-with-master
soloseng Apr 18, 2023
45817fa
++ yarn.lock
soloseng Apr 18, 2023
5ef81c0
Merge branch 'soloseng/sync-with-master' into soloseng/ganache-upgrade
soloseng Apr 18, 2023
d4dedb8
update ganache & ethereumjs version
soloseng Apr 21, 2023
eb47b9b
- removed resolutions
soloseng Apr 22, 2023
d1bbcb3
Merge branch 'soloseng/ganache-upgrade' into soloseng/update-web3-eth…
soloseng Apr 22, 2023
65e88fa
built using latest web3
soloseng Apr 22, 2023
609116a
Updated ganache config
soloseng Apr 25, 2023
6693173
Specify gas and await tx receipt
soloseng Apr 25, 2023
8d70315
updated dependencies to fix cross-fecth bind error
soloseng Apr 25, 2023
ba21b7b
Merge branch 'master' into soloseng/ganache-upgrade
soloseng Apr 26, 2023
4ba5ca8
updated yarn.lock
soloseng Apr 26, 2023
e09b884
updated node version in circleci docker file
soloseng Apr 26, 2023
3388635
updated expected error message
soloseng Apr 26, 2023
b4b0c70
ensure leading 0x instead of trimming
soloseng Apr 26, 2023
228ba70
increased jest version
soloseng Apr 26, 2023
aefc17f
Node 18.16.0
dckesler Apr 26, 2023
db11b41
- update node-fetch
soloseng Apr 26, 2023
bd3de96
Merge branch 'dckesler/ganache-upgrade' into soloseng/ganache-upgrade
soloseng Apr 26, 2023
885c8e0
Merge branch 'soloseng/update-web3-ethereumjs' into soloseng/ganache-…
soloseng Apr 26, 2023
e4d7a04
yarn installed using node 18.16.0
soloseng Apr 26, 2023
db592ca
Appease linter
soloseng Apr 26, 2023
4fb40d0
fixed import issue
soloseng Apr 26, 2023
e6d8842
use devchain chain copy
soloseng Apr 27, 2023
ce9f73f
using fixed jest version
soloseng Apr 27, 2023
4a699c5
disabled flake-traker
soloseng Apr 28, 2023
c8da898
generated CLI docs
soloseng Apr 28, 2023
96103b0
buypass jest_setup
soloseng Apr 28, 2023
2fc8f2b
ignored ts error due to properties mismatch
soloseng Apr 28, 2023
cf71f66
++ @types/node-fetch
soloseng Apr 28, 2023
12b2ae4
yarn.lock
soloseng Apr 28, 2023
9310a3d
using same @types/node-fetch where applicable
soloseng Apr 28, 2023
c021735
ts-ignored for abort-controller
soloseng Apr 28, 2023
6f776b7
Fix broken kit headers test
dckesler May 2, 2023
d752f69
temp force exit on contractkit test
soloseng May 3, 2023
cfe94ea
no detectOpenHandles
soloseng May 3, 2023
f3c0f89
Merge branch 'soloseng/force-exit-hanging-test' into soloseng/ganache…
soloseng May 3, 2023
d28cf49
Fix cross-fetch jest mocking issues
dckesler May 5, 2023
24a5f2c
lint fix
soloseng May 5, 2023
b1175ec
disabled verbose logs during testing
soloseng May 7, 2023
02fef9f
disabled rpc log in protocol test
soloseng May 7, 2023
e750d57
Disabled:
soloseng May 7, 2023
1ce3a12
removed disabled jobs from workflow
soloseng May 7, 2023
ad03f4c
supress test logs
soloseng May 7, 2023
42952af
disabled protocol test
soloseng May 7, 2023
ba1fa96
disabling flakey summary
soloseng May 7, 2023
9069cd5
disabled odis test
soloseng May 7, 2023
9c80542
increased resource class to xlarge
soloseng May 7, 2023
8431cc4
enaled protocol and odis CI test
soloseng May 7, 2023
d12b281
re-enabled
soloseng May 9, 2023
7955a97
Merge branch 'soloseng/modify-ci-config' into soloseng/ganache-upgrade
soloseng May 9, 2023
12ea5e9
enable phone-number-privacy test logs
soloseng May 9, 2023
d34d5d6
Fixing mocha issues in celotool tests
dckesler May 9, 2023
821fb8f
Change node to 18.14.0
dckesler May 10, 2023
2b93a03
Node 18.14.2
dckesler May 10, 2023
e8a0499
changed uniswap init code hash
soloseng May 10, 2023
f477d77
Revert "changed uniswap init code hash"
soloseng May 10, 2023
34861c1
fix unicode char in datetime format
soloseng May 11, 2023
a1e5c4c
Update e2e test docker image
dckesler May 11, 2023
8acee1a
verbose output
soloseng May 12, 2023
2620a2a
Pre-review cleanup
soloseng May 13, 2023
3b90f6d
appease linter
soloseng May 13, 2023
c63ffbe
removed dead code
soloseng May 13, 2023
6fa8c7f
deprecate defaultRpcCaller for httpRpcCaller
soloseng May 16, 2023
b2fd653
updated ganache-dev command
soloseng May 16, 2023
6808884
appease linter
soloseng May 16, 2023
0dcd40f
updated revert assertion with message
soloseng May 18, 2023
38685ac
downgraded truffle
soloseng May 18, 2023
a9cac7f
updated truffle version and config
soloseng May 19, 2023
ae8b2a0
add web3*@1.8.2 to resolutions
soloseng May 19, 2023
43f8a1c
Fixed stability test
soloseng May 19, 2023
b2c009b
removed resolutions
soloseng May 20, 2023
3e11de3
updated yarn lock
soloseng May 20, 2023
50bec2a
updated governance/network test revert messages
soloseng May 20, 2023
bccd968
updated protocol common test revert assertion msg
soloseng May 20, 2023
04a3d2c
appease linter
soloseng May 20, 2023
eca7b4f
using assertRevertWithReason
soloseng May 20, 2023
9368c6b
using assertRevertWithReason in governance/voting
soloseng May 20, 2023
8a64112
angry linter
soloseng May 20, 2023
6f70d37
using assertRevertWithReason in identity/
soloseng May 23, 2023
bff7b5d
fix linter issue
soloseng May 23, 2023
a408c1d
using `@ethereumjs/rlp` for RLP encoding
soloseng May 24, 2023
164ff0e
linter fix
soloseng May 24, 2023
2b5a71e
updated web3* dependencies
soloseng May 25, 2023
e83d779
specify type of transaction
soloseng May 25, 2023
b15eee7
removed verbose output
soloseng May 25, 2023
2fcf913
added `assertRevertWithoutReason()`
soloseng May 26, 2023
7221844
linting fix
soloseng May 26, 2023
77aa86f
added revert without msg for identity test
soloseng May 26, 2023
b30972d
updated deprecated functions
soloseng May 26, 2023
fde198b
distinguish between
soloseng May 27, 2023
1c2431e
fixed typing ignore
soloseng May 27, 2023
ce55171
specified gas, as gas estimations fails
soloseng May 27, 2023
39268e7
Merge branch 'master' into soloseng/sync-master
soloseng May 27, 2023
f39af3b
updated revert message in test
soloseng May 27, 2023
de797fa
updated yarn lock
soloseng May 27, 2023
033d6f5
updated yarn lock again
soloseng May 27, 2023
2a816cc
change docker image path
soloseng May 27, 2023
94cac6b
updated revert msg to match contract
soloseng May 27, 2023
224b4ca
Merge branch 'soloseng/sync-master' into soloseng/ganache-upgrade
soloseng May 27, 2023
c4e58e7
updated docs to match current node version
soloseng May 30, 2023
269aa7b
tracking issue in comment
soloseng May 30, 2023
74960e6
specified chain id
soloseng May 30, 2023
7ecaa3c
revert to default verbose output
soloseng May 30, 2023
998e981
removed debud logging
soloseng May 31, 2023
ab8296f
Merge branch 'master' into soloseng/ganache-upgrade
soloseng May 31, 2023
9a85b11
Merge branch 'master' into soloseng/ganache-upgrade
jcortejoso Jun 2, 2023
f0de102
GH Workflows run in node18 runners
jcortejoso Jun 2, 2023
12d6c6a
Force new node cache
jcortejoso Jun 2, 2023
060ffa4
Disable flake-tracker
jcortejoso Jun 2, 2023
f5502bb
prettify
jcortejoso Jun 2, 2023
7246063
Merge branch 'master' into soloseng/ganache-upgrade
soloseng Jun 3, 2023
4d3aee6
Updated test to revert with message
soloseng Jun 3, 2023
1de9f29
Merge branch 'master' into soloseng/ganache-upgrade
soloseng Jun 6, 2023
a3564c4
Merge branch 'master' into soloseng/ganache-upgrade
soloseng Jun 7, 2023
373fda7
quiet test
soloseng Jun 7, 2023
09c58c3
Merge branch 'master' into soloseng/ganache-upgrade
soloseng Jun 8, 2023
34280de
Merge branch 'master' into soloseng/ganache-upgrade
soloseng Jun 9, 2023
48c422c
fixed build errors
soloseng Jun 9, 2023
49f216d
updated scripts to better handle ts & js files
soloseng Jun 9, 2023
f6d071a
moved `artifactSingleton` file to lib/
soloseng Jun 9, 2023
cd45852
Merge branch 'master' into soloseng/ganache-upgrade
soloseng Jun 12, 2023
a27e86d
Merge branch 'master' into soloseng/ganache-upgrade
soloseng Jun 14, 2023
c386b13
added transaction type when using mento artifacts
soloseng Jun 14, 2023
93dc7d5
fix Migration test
soloseng Jun 14, 2023
31f5840
allow submodules in e2e matrix
soloseng Jun 14, 2023
4eb236d
Merge branch 'master' into soloseng/ganache-upgrade
jcortejoso Jun 20, 2023
c0ee6fb
python2 -> python (3)
jcortejoso Jun 20, 2023
6c8f094
using nvm to switch to node12 for pre-release test
soloseng Jun 26, 2023
22a2a05
∆ to trigger GH action
soloseng Jun 26, 2023
4b6629c
∆ to trigger full test in GH actions
soloseng Jun 26, 2023
acafbac
Using nvm for circleci image
jcortejoso Jun 26, 2023
db5df3c
Do not use nvm with circleci
jcortejoso Jun 26, 2023
910a706
use node12 to generate old release devchain
soloseng Jun 26, 2023
57f0009
reset and reinstall before cleaning
soloseng Jun 26, 2023
8a1fcff
set python2 in release branch
soloseng Jun 26, 2023
463a42c
installed python2
soloseng Jun 26, 2023
9a16941
added log
soloseng Jun 26, 2023
b886aa5
removed python2 install script
soloseng Jun 26, 2023
de5b770
set new release tag
soloseng Jun 26, 2023
f167a08
trigger all test
soloseng Jun 26, 2023
d44d920
WIP comments
soloseng Jun 26, 2023
d7dad8b
trigger all test
soloseng Jun 27, 2023
fbc89cb
CircleCi Build pre-protocol with node12
jcortejoso Jun 27, 2023
cdf6dc3
Circle node12 fix
jcortejoso Jun 27, 2023
16669e5
Adding python 2 and 3 to circleci image
jcortejoso Jun 27, 2023
c9a3637
run devchain from tar in detached mode
soloseng Jun 27, 2023
8329f64
++ comments
soloseng Jun 27, 2023
53096ff
updated release tag in circleCI config
soloseng Jun 28, 2023
3880bb2
Replace pull_request by pull_request_target
jcortejoso Jun 29, 2023
0aadd4c
bump MTWdeployer patch version
soloseng Jun 29, 2023
0e49b7b
testing bypass dryrun
soloseng Jun 29, 2023
fa043b9
loggin and force CI run
soloseng Jun 29, 2023
09d2681
removed false param
soloseng Jun 29, 2023
3fb39b8
revert change and added try catch
soloseng Jun 29, 2023
bc2c108
moved await
soloseng Jun 29, 2023
7050b50
added type to tx detail
soloseng Jun 29, 2023
037249f
included tx type in contract deployment
soloseng Jun 29, 2023
a6b7fff
increased logging level in ganache and truffle
soloseng Jun 30, 2023
5d56995
specified gas to deployment tx
soloseng Jun 30, 2023
18ae7b3
removed truffle debug logging
soloseng Jun 30, 2023
787392f
keep chaincopy
soloseng Jun 30, 2023
dac608b
removed debug logs
soloseng Jun 30, 2023
7d2e5c5
clean up redundant install
soloseng Jun 30, 2023
2b4ffb1
revert GH action trigger on current branch push
soloseng Jun 30, 2023
ffb07c9
remove comments
soloseng Jun 30, 2023
9eadf98
remove gas specfication
soloseng Jun 30, 2023
1945d60
Merge branch 'master' into soloseng/ganache-upgrade
soloseng Jul 10, 2023
3bde778
Merge branch 'master' into soloseng/ganache-upgrade
soloseng Jul 10, 2023
5a964cf
updated node version in docs
soloseng Jul 11, 2023
e553ae0
unskip migration test
soloseng Jul 11, 2023
6b3f017
PR feedback
soloseng Jul 14, 2023
81d87a3
revert back to skip
soloseng Jul 15, 2023
f6b2146
∆ forked packages to celo namespace
soloseng Jul 17, 2023
0e68b2c
reinstalled
soloseng Jul 17, 2023
7340798
Merge branch 'master' into soloseng/ganache-upgrade
jcortejoso Jul 18, 2023
d0fd9c9
cleanup TODO and comments
soloseng Jul 19, 2023
61752b0
python -> python3
jcortejoso Jul 19, 2023
3fae1da
updated node base images to 18
jcortejoso Jul 19, 2023
6c88c24
Merge branch 'master' into soloseng/ganache-upgrade
jcortejoso Jul 19, 2023
18b8c46
python -> python3
jcortejoso Jul 19, 2023
41feecb
Merge branch 'soloseng/ganache-upgrade' of github.com:celo-org/celo-m…
jcortejoso Jul 19, 2023
672c5e4
Updated netcat dependency
jcortejoso Jul 19, 2023
074a074
Fix build
jcortejoso Jul 19, 2023
f19034d
Fix build docker
jcortejoso Jul 19, 2023
06c90f1
force GH action test
soloseng Jul 19, 2023
b2fab0a
WIP adding CIP42 /eip1559 support
aaronmgdr Aug 2, 2023
0212808
WIP
aaronmgdr Aug 3, 2023
c50a9bd
Merge branch 'master' into aaronmgdr/cip42
aaronmgdr Aug 3, 2023
fbbf2fa
fix build, move types to type file
aaronmgdr Aug 3, 2023
b336e54
remove outdated and removed method calls to kit from cli
aaronmgdr Aug 3, 2023
efd1aad
more data for test
aaronmgdr Aug 3, 2023
f761667
better errors and fixed tests
aaronmgdr Aug 4, 2023
e818f6e
fix signing, improve tests
aaronmgdr Aug 5, 2023
97f16b2
test signing and parsing transaction compared to viem
aaronmgdr Aug 8, 2023
966b494
more viem comparison work .. failing
aaronmgdr Aug 8, 2023
32d28c8
latest
aaronmgdr Aug 10, 2023
381d962
help
aaronmgdr Aug 10, 2023
a97970f
Merge branch 'master' into aaronmgdr/cip42
aaronmgdr Aug 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ orbs:
parameters:
run-workflow-general:
type: boolean
default: false
default: false
run-workflow-npm-install:
type: boolean
default: false
default: false
run-workflow-protocol-coverage:
type: boolean
default: false
default: false
# When you need to force a rebuild of the node modules cache then bump this version
node-modules-cache-version:
type: integer
Expand Down Expand Up @@ -910,7 +910,7 @@ workflows:
version: 2
celo-monorepo-build:
# Contitionally triggered
when:
when:
or: [<< pipeline.parameters.run-workflow-general >>]
jobs:
- install_dependencies
Expand Down Expand Up @@ -1015,15 +1015,15 @@ workflows:
- lint-checks
npm-install-testing-cron-workflow:
# Contitionally triggered
when:
when:
or: [<< pipeline.parameters.run-workflow-npm-install >>]
jobs:
- test-typescript-npm-package-install
- test-utils-npm-package-install
- test-contractkit-npm-package-install
- test-celocli-npm-package-install
protocol-testing-with-code-coverage-cron-workflow:
when:
when:
or: [<< pipeline.parameters.run-workflow-protocol-coverage >>]
jobs:
- install_dependencies
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/circleci.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be changed.

It is currently preventing GH action from running.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah when i started i branched off the node 18 branch. im gonna try moving my commits to a new branch off master

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ on:
push:
branches:
- master
pull_request:
# TODO (soloseng): remove before merge
- soloseng/ganache-upgrade
# TODO(jcortejoso): Replace by pull_request
pull_request_target:
branches:
- master

Expand Down
3 changes: 0 additions & 3 deletions packages/cli/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ export abstract class BaseCommand extends Command {

const setStableTokenGas = async (stable: StableToken) => {
await this.kit.setFeeCurrency(stableTokenInfos[stable].contract)
await this.kit.updateGasPriceInConnectionLayer(
await this.kit.registry.addressFor(stableTokenInfos[stable].contract)
)
}
if (Object.keys(StableToken).includes(gasCurrencyConfig)) {
await setStableTokenGas(StableToken[gasCurrencyConfig as keyof typeof StableToken])
Expand Down
9 changes: 3 additions & 6 deletions packages/cli/src/transfer-stable-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BaseCommand } from './base'
import { newCheckBuilder } from './utils/checks'
import { displaySendTx, failWith } from './utils/cli'
import { Flags } from './utils/command'
import { stableTokenInfos } from '@celo/contractkit/src/celo-tokens'

export abstract class TransferStableBase extends BaseCommand {
static flags = {
Expand Down Expand Up @@ -35,7 +36,7 @@ export abstract class TransferStableBase extends BaseCommand {
} catch {
failWith(`The ${this._stableCurrency} token was not deployed yet`)
}
await this.kit.updateGasPriceInConnectionLayer(stableToken.address)
await this.kit.setFeeCurrency(stableTokenInfos[this._stableCurrency].contract)

const tx = res.flags.comment
? stableToken.transferWithComment(to, value.toFixed(), res.flags.comment)
Expand All @@ -48,11 +49,7 @@ export abstract class TransferStableBase extends BaseCommand {
this.kit.connection.defaultFeeCurrency === stableToken.address,
async () => {
const gas = await tx.txo.estimateGas({ feeCurrency: stableToken.address })
// TODO: replace with gasPrice rpc once supported by min client version
const { gasPrice } = await this.kit.connection.fillGasPrice({
gasPrice: '0',
feeCurrency: stableToken.address,
})
const gasPrice = await this.kit.connection.gasPrice(stableToken.address)
const gasValue = new BigNumber(gas).times(gasPrice as string)
const balance = await stableToken.balanceOf(from)
return balance.gte(value.plus(gasValue))
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/base/src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const normalizeAddressWith0x = (a: Address) => ensureLeading0x(a).toLower

export const trimLeading0x = (input: string) => (input.startsWith('0x') ? input.slice(2) : input)

export const ensureLeading0x = (input: string) => (input.startsWith('0x') ? input : `0x${input}`)
export const ensureLeading0x = (input: string): `0x${string}` =>
input.startsWith('0x') ? (input as `0x${string}`) : (`0x${input}` as const)

// Turns '0xce10ce10ce10ce10ce10ce10ce10ce10ce10ce10'
// into ['ce10','ce10','ce10','ce10','ce10','ce10','ce10','ce10','ce10','ce10']
Expand Down
46 changes: 46 additions & 0 deletions packages/sdk/cip42changees
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
TopLine Changes

* Add support for CIP42 and EIP1559 Transactions
* Prefer EIP1559 if no feeCurrency and CIP42 if using feeCurrency, Old CeloLegacy transations still supported (set the gasPrice explicitly) but discouraged
* upgrade Web3 dependency

## @celo/connect

* gasPrice is no longer an option on config. setting 0 (or any empty value) for gasPrice in transaction will result in maxFeePerGas and maxPriorityFee per gas being set on the transaction

* likewise gasPrice is no longer settable on the connection itself

* (note that the gasPrice function for fetching price from node is NOT affected)

* replace connection.fillGasPrice with connection.setFeeMarketGas

* add inputAccessListFormatter

* remove deprecated setGasPriceForCurrency

* EncodedTransaction Type now supports CIp42 and EIP1559 transactions

* inputCeloTxFormater now returns type FormattedCeloTx although apart from support for cip42 and eip1559 tx the data returned hasnt changed

* numberToHex, ensureLeading0x, inputAddressFormatter now are typed to return `0x{string}` instead of just string

* added parseAccessList and inputAccessListFormatter for converting accessList from json to array of array and back

* RLPEncodedTx now types its transaction field as FormattedTransaction this is more accurate than the CeloTX type it previously had

## kit

* removed gasPriceSuggestionMultiplier == gas price from rpc no longer multipled by 5

* remove kit.fillGasPrice

* remove updateGasPriceInConnectionLayer

* remove kit.gasPrice

## @celo/wallet-base

* extractSignature now throws if the length of provided tx is not correct
* extractSignature was incorrectly typed to return Buffers for r and s values

* ensureLeading0x now types output to be `0x{string}`
5 changes: 3 additions & 2 deletions packages/sdk/connect/src/celo-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class MockWallet implements ReadOnlyWallet {
}
signTransaction(_txParams: CeloTx): Promise<EncodedTransaction> {
return Promise.resolve({
raw: 'mock',
raw: '0xmock',
tx: {
type: 'celo-legacy',
nonce: 'nonce',
gasPrice: 'gasPrice',
gas: 'gas',
Expand Down Expand Up @@ -193,7 +194,7 @@ describe('CeloProvider', () => {

describe('but tries to use it with a different account', () => {
interceptedByCeloProvider.forEach((method: string) => {
test(`fowards the call to '${method}' to the original provider`, (done) => {
test(`forwards the call to '${method}' to the original provider`, (done) => {
const payload: JsonRpcPayload = {
id: 0,
jsonrpc: '2.0',
Expand Down
67 changes: 37 additions & 30 deletions packages/sdk/connect/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { bufferToHex } from '@ethereumjs/util'
import debugFactory from 'debug'
import Web3 from 'web3'
import { AbiCoder } from './abi-types'
import { assertIsCeloProvider, CeloProvider } from './celo-provider'
import { CeloProvider, assertIsCeloProvider } from './celo-provider'
import {
Address,
Block,
Expand Down Expand Up @@ -34,15 +34,14 @@ import {
import { hasProperty } from './utils/provider-utils'
import { getRandomId, HttpRpcCaller, RpcCaller } from './utils/rpc-caller'
import { TxParamsNormalizer } from './utils/tx-params-normalizer'
import { toTxResult, TransactionResult } from './utils/tx-result'
import { TransactionResult, toTxResult } from './utils/tx-result'
import { ReadOnlyWallet } from './wallet'

const debugGasEstimation = debugFactory('connection:gas-estimation')

type BN = ReturnType<Web3['utils']['toBN']>
export interface ConnectionOptions {
gasInflationFactor: number
gasPrice: string
feeCurrency?: Address
from?: Address
}
Expand All @@ -58,16 +57,11 @@ export class Connection {
readonly paramsPopulator: TxParamsNormalizer
rpcCaller!: RpcCaller

/** @deprecated no longer needed since gasPrice is available on node rpc */
private currencyGasPrice: Map<Address, string> = new Map<Address, string>()

constructor(readonly web3: Web3, public wallet?: ReadOnlyWallet, handleRevert = true) {
web3.eth.handleRevert = handleRevert

this.config = {
gasInflationFactor: 1.3,
// gasPrice:0 means the node will compute gasPrice on its own
gasPrice: '0',
}

const existingProvider: Provider = web3.currentProvider as Provider
Expand Down Expand Up @@ -125,14 +119,6 @@ export class Connection {
return this.config.gasInflationFactor
}

set defaultGasPrice(price: number) {
this.config.gasPrice = price.toString(10)
}

get defaultGasPrice() {
return parseInt(this.config.gasPrice, 10)
}

/**
* Set the ERC20 address for the token to use to pay for transaction fees.
* The ERC20 must be whitelisted for gas.
Expand Down Expand Up @@ -224,7 +210,7 @@ export class Connection {
*/
sendTransaction = async (tx: CeloTx): Promise<TransactionResult> => {
tx = this.fillTxDefaults(tx)
tx = this.fillGasPrice(tx)
tx = await this.setFeeMarketGas(tx)

let gas = tx.gas
if (gas == null) {
Expand All @@ -244,7 +230,7 @@ export class Connection {
tx?: Omit<CeloTx, 'data'>
): Promise<TransactionResult> => {
tx = this.fillTxDefaults(tx)
tx = this.fillGasPrice(tx)
tx = await this.setFeeMarketGas(tx)

let gas = tx.gas
if (gas == null) {
Expand Down Expand Up @@ -341,20 +327,27 @@ export class Connection {
sendSignedTransaction = async (signedTransactionData: string): Promise<TransactionResult> => {
return toTxResult(this.web3.eth.sendSignedTransaction(signedTransactionData))
}
// if neither gas price nor feeMarket fields are present set them.
async setFeeMarketGas(tx: CeloTx): Promise<CeloTx> {
// default to the current values
const calls = [Promise.resolve(tx.maxFeePerGas), Promise.resolve(tx.maxPriorityFeePerGas)]

/** @deprecated no longer needed since gasPrice is available on node rpc */
fillGasPrice(tx: CeloTx): CeloTx {
if (tx.feeCurrency && tx.gasPrice === '0' && this.currencyGasPrice.has(tx.feeCurrency)) {
return {
...tx,
gasPrice: this.currencyGasPrice.get(tx.feeCurrency),
if ((isEmpty(tx.gasPrice) && isEmpty(tx.maxFeePerGas)) || isEmpty(tx.maxPriorityFeePerGas)) {
if (isEmpty(tx.maxFeePerGas)) {
calls[0] = this.gasPrice(tx.feeCurrency)
}
if (isEmpty(tx.maxPriorityFeePerGas)) {
calls[1] = this.rpcCaller.call('eth_maxPriorityFeePerGas', []).then((rpcResponse) => {
return rpcResponse.result
})
}
}
return tx
}
/** @deprecated no longer needed since gasPrice is available on node rpc */
async setGasPriceForCurrency(address: Address, gasPrice: string) {
this.currencyGasPrice.set(address, gasPrice)
const [maxFeePerGas, maxPriorityFeePerGas] = await Promise.all(calls)
return {
...tx,
maxFeePerGas,
maxPriorityFeePerGas,
}
}

estimateGas = async (
Expand Down Expand Up @@ -508,7 +501,6 @@ export class Connection {
const defaultTx: CeloTx = {
from: this.config.from,
feeCurrency: this.config.feeCurrency,
gasPrice: this.config.gasPrice,
}

return {
Expand All @@ -522,3 +514,18 @@ export class Connection {
this.web3.currentProvider.stop()
}
}

function isEmpty(value: string | undefined | number | BN) {
return (
value === 0 ||
value === undefined ||
value === null ||
value === '0' ||
(typeof value === 'string' &&
(value.toLowerCase() === '0x' || value.toLowerCase() === '0x0')) ||
Web3.utils.toBN(value.toString()).eq(Web3.utils.toBN(0))
)
}
export function isPresent(value: string | undefined | number | BN) {
return !isEmpty(value)
}
Loading