-
Notifications
You must be signed in to change notification settings - Fork 369
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
Contract Kit 2.0.0 #9127
Merged
Merged
Contract Kit 2.0.0 #9127
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Everything from celo/utils which used google-libphonenumber or country.js has been move here include the io.ts file.
…e is published since faucet must depend only on published packages
# Conflicts: # packages/attestation-service/package.json # packages/faucet/package.json # packages/sdk/CHANGELOG.md # packages/sdk/identity/package.json # packages/sdk/phone-utils/package.json # packages/sdk/utils/package.json # packages/sdk/utils/src/io.ts # yarn.lock
aaronmgdr
requested review from
asaj,
critesjosh,
eelanagaraj,
gastonponti,
mcortesi and
timmoreton
as code owners
December 17, 2021 17:38
Make it so nothing inside of the contractKit packgaes needs a kit to be passed into its constructor. instead use Connection or WrapperCache or move functions close to their source. This should alllow us to be more selective and decide to one ContractWrapper without needing to initialize a kit which itself would require initializing all bunch of other data. This should lead to the ability to only import parts of contract kit. and lead to small bundle sizes
dckesler
approved these changes
Apr 21, 2022
* Add Basic Readme files to the sdk packages * WIP readmes * add more readmes, provide descriptions of wallet packages * Set packages homepage to the sdk docs site * mark functions as deprecated or internal * Add details to typdoc comments, set readmes for a few packages * mark functions as internal and other cleanup * lint * clean up docs * edits * formatting * formatting * link to example repo * improve readme for kit * Update packages/sdk/connect/readme.md Co-authored-by: Camila Rondinini <crondinini@gmail.com> * Update packages/sdk/connect/readme.md Co-authored-by: Camila Rondinini <crondinini@gmail.com> * its a wrapper not technically a contract * Update packages/sdk/contractkit/README.md Co-authored-by: Camila Rondinini <crondinini@gmail.com> * Add reference to upgrade Guide in Changelog * Update packages/sdk/connect/src/utils/abi-utils.ts Co-authored-by: Camila Rondinini <crondinini@gmail.com> * Fix missing contract in readme example * generate docs Co-authored-by: Josh <critesjosh@gmail.com> Co-authored-by: Camila Rondinini <crondinini@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Major Version change to SDK packages.
Goals
Bundle Size of the flagship @celo/contractkit package is as of latest version 3.2MB minified Considering we are advertising this as being mobile that size is far to big. (15 seconds to download on 3g network)
Minimize Breaking Changes
This is not a complete rewrite. I want to make changes only where it made a big different to bundle size and the migration would not be too difficult
Result
As of Alpha 4 Bundlephobia lists the bundle size as 1.7MB minified (which is still very big) Most of this comes from A) our contract ABIs/wrappers and B) Web3 itself. Therefore I would say we have reached the limit of how small this will get without drastic changes. However for Dapps needing a subset of contractkit there are alternatives
MiniContractKit
andConnect
How We Got there
Prime source of bloat was due to external packages imported via @celo/utils. To fix I split off 2 packages
@celo/phone-utils
Functions which depend on either
google-libphonenumber
orcountry-data
@celo/cryptographic-utils
Functions which depend on
bigi
,bip39
bip32
,bls12377js
buffer-reverse
Refactoring
Third pillar was refactoring of
WrapperCache
AddressRegistry
CeloTokens
, and**Wrapper
s so that they did not need a fullContractKit
as a Parameter. This means it is now possible to use just the parts of the Kit that one needs. For how this lead to breaking changes see that section.MiniKit
Furthermore it enabled the Creation of
MiniContractKit
which is a Kit that only provides access toAccountsWrapper
The Token Wrappers, The Exchange Wrappers, andGasPriceMinimumWrapper
. It gives no access to nor uses theWeb3ContractsCache
use Like
MiniKit has no Access to
ValidatorsWrapper
CeloTokens#isStableTokenContract
This is now exported as a standalone function (kept on the instance for backwards compatibility)
ValidatorsWrapper
Functions that used the validator wrapper but lived on the ContractKit have been moved here (with forwarding to kit for backwards compatibility)
@celo/base
enum for
StableTokens
Token
CeloTokens
move there from @celo/contractkit/celo-tokens (reexports for backwards compatibility@celo/connect
Other changes
sideEffects: false
Tested
Related issues
Fixes Break up Utils Package #6189
Backwards compatibility
Breaking Changres
@celo/contractkit
Most changes here are about eliminating the need to construct an entire kit to use classes and functions. and thus giving us the dream of a modular sdk
AddressRegistry
now takes an
Connection
instance instead of akit
CeloTokens
no longer requires kit instead requires a Class implementing
ContractCacheType
to be passed. Examples areWrapperCache
orCeloTokensCache
Wrappers
Rather than take the full Kit Wrappers now construct like
The
WrapperCache
takes care of this while constructing them and most likely there will not be many situations where Wrappers were constructed directly given they needed a kit before.AccountsWrapper
authorizeValidatorSigner
method now requires aValidatorsWrapper
be passed in as final argument.Web3ContractCache
Instead of a
kit
requires only aAddressRegistry
(uses AddressRegistry's web3 instances)@celo/utils
Anyone who was importing {PhoneNumberUtils, getCountryEmoji, getPhoneHash, LocalizedCountry, Countries, validatePhone, validateInput } from "@celo/utils" must now import from @celo/phone-utils
Furthermore the io.ts file was split up and E164PhoneNumberType, AttestationServiceStatusResponseType, AttestationServiceTestRequestType, AttestationRequestType, GetAttestationRequestType, AttestationRequest, AttestationResponseType, AttestationResponse must be imported from @celo/phone-utils too.
This is because all those types indirectly depend on E164PhoneNumberType which uses isE164NumberStrict. One alternative is to change this to use isE164Number from celo/base which is regeex based instead but im not sure of the affects of that. but it would greatly simplify a lot here.
Documentation
Still in progress I Am adding readmes to all subpackages, making sure functions have typedoc annotations and new packages have typedoc setup.
I plan to write a blog post / migration guide on docs.celo.org
My goal is to have this all done before celo connect. and have beta 1 released before or durin.