-
Notifications
You must be signed in to change notification settings - Fork 303
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
Add Migration Guide for ContractKit v2 #307
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
15e4028
Add Migration Guide for contractKit v2
aaronmgdr 1e222ca
Improve flow of guide
aaronmgdr a7067d8
add to sidebar and fix up descriptions
aaronmgdr 1bb929a
some edits
critesjosh bba6791
edits
critesjosh 0a950f8
minor edits
critesjosh b1f6f21
update gtag location
critesjosh 6c623c1
update docusaurus version
critesjosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
233 changes: 233 additions & 0 deletions
233
docs/developer-resources/contractkit/migrating-to-contractkit-v2.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
--- | ||
title: Migrating to ContractKit v2.0 | ||
description: How to migrate from v1 to v2 ContractKit suite of packages and make use of their latest features. | ||
slug: /developer-guide/contractkit/migrating-to-contractkit-v2 | ||
--- | ||
|
||
How to migrate from v1 to v2 of the Celo SDK suite of packages and make use of their latest features. | ||
|
||
___ | ||
|
||
## Why v2? | ||
|
||
### Bundlesize | ||
|
||
The primary motivation in creating v2 was reduced bundlesize and increased modularity. The massive package size for `@celo/contractkit` has been an elephant in the room and source of dissonance for looking to build mobile first dApps. As of 1.5.2 bundlephobia list the minified size at 3.7MB. 2.0.0 comes in at 1.7MB. still big yet we have a few more tricks. First the packages have been all marked as `sideEffects:false`, a `kit` instance is no longer required to any classes in the contractkit package, and the introduction of `MiniContractKit`. | ||
|
||
### Modularity | ||
|
||
#### `sideEffects:false` | ||
|
||
Tells your bundler it can safely only include the code that is explicitly used, reducing bundlesize. | ||
|
||
#### `kit` no longer needed by everything | ||
|
||
In v1 Almost everything required a `kit` instance to be passed to its constructor. Effectively this meant it was impossible to use any of the classes in @celo/contractkit alone. | ||
|
||
In v2 AddressRegistry, Wrappers, WrapperCache, and more can all be constructed using mostly just a `Connection` (sometimes other arguments too). | ||
|
||
#### `MiniContractKit` | ||
|
||
The prize of no longer needing a full `kit` is that it became possible to create a slimed down minimal viable ContractKit. | ||
|
||
`MiniContractKit` provides a subset of ContractKit features with the same interface. For many dapps it will be a drop in opt-in change (eg `import {newKit, ContractKit} from "@celo/contractkit/lib/mini/kit`). It reduces size by only including access to `Accounts, GasPriceMinimum, StableToken*, Exchange* and GoldToken` wrappers and contracts. It can `setFeeCurrency`, look up info about the current account and, like full Contractkit, it delegates most functionality to `connection`. | ||
|
||
## Get Started | ||
|
||
Upgrade your project packages to the latest (in this case release beta, but anything over 2 will work when it's out of beta). For example, with ContractKit and Celo utils: | ||
|
||
`yarn add @celo/contractkit@beta @celo/utils@beta` | ||
|
||
If you are directly importing any other `@celo/*` packages, upgrade them as well. | ||
|
||
If you need them, append `@celo/phone-utils@beta` `@celo/cryptographic-utils@beta`. | ||
|
||
*(see section on breaks in [@celo/utils](#celoutils) to know if you need them)* | ||
|
||
## Breaking changes | ||
|
||
Because of how we publish packages, all packages will be upgraded to v2. However not all packages will have breaking changes. Breaking changes are limited to: | ||
|
||
- [@celo/contractkit](#celocontractkit) | ||
- [@celo/utils](#celoutils) | ||
|
||
### @celo/contractkit | ||
|
||
Most changes are about eliminating the need to construct an entire kit to use other classes and functions. | ||
|
||
#### IdentityMetadataWrapper (idendity/metadata.ts) | ||
|
||
This had functions that took a `kit` as a parameter. Now it takes an AccountsWrapper class. | ||
|
||
This change was done so that `kit` was not required to be passed into all the classes and functions that use `IdentityMetadataWrapper`. | ||
|
||
*v1 | ||
|
||
```typescript | ||
IdentityMetadataWrapper.fetchFromURL(kit, url) | ||
|
||
IdentityMetadataWrapper.fromFile(kit, path) | ||
|
||
IdentityMetadataWrapper.verifySignerForAddress(kit, hash, signature, address) | ||
IdentityMetadataWrapper.fromRawString(kit, rawData) | ||
``` | ||
|
||
*v2 | ||
|
||
```typescript | ||
const accounts = await kit.contracts.getAccounts() | ||
|
||
IdentityMetadataWrapper.fetchFromURL(accounts, url) | ||
|
||
IdentityMetadataWrapper.fromFile(accounts, path) | ||
|
||
IdentityMetadataWrapper.verifySignerForAddress(accounts, hash, signature, address) | ||
IdentityMetadataWrapper.fromRawString(accounts, rawData) | ||
``` | ||
|
||
#### AddressRegistry | ||
|
||
Now takes an `Connection` instance instead of a `kit` instance. | ||
|
||
#### CeloTokens | ||
|
||
No longer requires `kit`, instead it requires a class implementing `ContractCacheType` to be passed in. Examples are `WrapperCache` or `CeloTokensCache`. | ||
|
||
#### Wrappers | ||
|
||
**Note: If you were constructing wrappers with `kit.contracts.getX` no change is required.** | ||
|
||
Rather than take the full Kit Wrappers, now construct it like: | ||
|
||
```javascript | ||
// Most Common | ||
constructor(connection: Connection, contract: Contract) | ||
// The Voting Contracts (Governance, Election, Validator, LockedGold, Slashers, and Attestations | ||
constructor(connection: Connection, contract: Contract, wrapperCache: WrapperCache) | ||
// Sorted Oracles | ||
constructor(connection: Connection, contract: Contract, addressRegistry: AddressRegistry) | ||
``` | ||
|
||
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 a `ValidatorsWrapper` be passed in as final argument. | ||
|
||
*v1* | ||
|
||
```ts | ||
const accountsInstance = await kit.contracts.getAccountsWrapper() | ||
|
||
accountsInstance.authorizeValidatorSigner(signer, sig) | ||
``` | ||
|
||
*v2* | ||
|
||
```ts | ||
|
||
const accountsInstance = await kit.contracts.getAccountsWrapper() | ||
const validatorsInstance = await kit.contracts.getValidatorsWrapper() | ||
|
||
accountsInstance.authorizeValidatorSigner(signer, sig, validatorsInstance) | ||
|
||
``` | ||
|
||
#### Web3ContractCache | ||
|
||
Instead of a `kit` instance, it requires only a `AddressRegistry` (uses AddressRegistry's web3 instances). | ||
|
||
### @celo/utils | ||
|
||
Most of the size savings came from removing functionality from `@celo/utils` into two new packages `@celo/phone-utils` and `@celo/cryptographic-utils` | ||
|
||
So depending on what you used you will need to add one or both to your package.json. | ||
|
||
#### Phone Utils | ||
|
||
If your packages imports any of the following from `@celo/utils` you will need to change the import to `@celo/phone-utils` | ||
|
||
##### from countries.ts | ||
|
||
- `CountryNames` | ||
- `LocalizedCountry` | ||
- `Countries` | ||
|
||
##### from getCountryEmoji.ts | ||
|
||
- `getCountryEmoji` | ||
|
||
##### from getPhoneHash.ts | ||
|
||
- default (getPhoneHash) | ||
|
||
##### from inputValidation.ts | ||
|
||
- `validatePhone` | ||
- `validateInput` | ||
|
||
##### from io.ts | ||
|
||
- `AttestationRequestType` | ||
- `AttestationResponseType` | ||
- `AttestationResponse` | ||
- `AttestationServiceTestRequestType` | ||
- `AttestationServiceTestRequest` | ||
- `E164PhoneNumberType` | ||
- `E164Number` | ||
- `GetAttestationRequestType` | ||
|
||
##### from phoneNumbers.ts | ||
|
||
- `getCountryCode` | ||
- `getRegionCode` | ||
- `getRegionCodeFromCountryCode` | ||
- `getDisplayPhoneNumber` | ||
- `getDisplayNumberInternational` | ||
- `getE164DisplayNumber` | ||
- `getE164Number` | ||
- `isE164NumberStrict` | ||
- `parsePhoneNumber` | ||
- `getExampleNumber` | ||
|
||
#### Cryptographic-utils | ||
|
||
If your packages imports any of the following from `@celo/utils` you will need to change the import to `@celo/cryptographic-utils` | ||
|
||
##### from account.ts | ||
|
||
- `generateKeys` | ||
- `generateKeysFromSeed` | ||
- `generateDeterministicInviteCode` | ||
- `generateSeed` | ||
- `generateMnemonic` | ||
- `validateMnemonic` | ||
- `invalidMnemonicWords` | ||
- `normalizeMnemonic` | ||
- `formatNonAccentedCharacters` | ||
- `getAllLanguages` | ||
- `mnemonicLengthFromStrength` | ||
- `detectMnemonicLanguage` | ||
- `suggestMnemonicCorrections` | ||
|
||
##### from bls.ts | ||
|
||
- `BLS_PUBLIC_KEY_SIZE` | ||
- `BLS_POP_SIZE` | ||
- `blsPrivateKeyToProcessedPrivateKey` | ||
- `getBlsPublicKey` | ||
- `getBlsPoP` | ||
|
||
##### from commentEncryption.ts | ||
|
||
- `EncryptionStatus` | ||
- `encryptData` | ||
- `decryptData` | ||
- `encryptComment` | ||
- `decryptComment` | ||
|
||
##### from dataEncryption.ts | ||
|
||
- `compressedPubKey` | ||
- `decompressPublicKey` | ||
- `deriveDek` |
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this referring to breaking changes? I don't see any info about breaking changes in the utils section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats the largest part.
Maybe its not clear since i used to new package names to group the breaking changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I get it now, thanks