| @polygonlabs/pos-sdk | major |
|---|
Rewrites the Polygon PoS bridge SDK from the ground up. The package is renamed from @maticnetwork/maticjs to @polygonlabs/pos-sdk. The plugin layer is removed; consumers wrap their existing viem / ethers v5 / ethers v6 client with a per-library adapter factory imported from a subpath (viemAdapter from @polygonlabs/pos-sdk/viem, etc.) and pass it to POSClient.init({ parent, child }) — the main entry pulls in no web3 library, so you ship only the one you use. The SDK is fully cross-environment: no Buffer, no node:* imports, no dynamic imports — it runs unchanged in Node ≥20 and modern browsers. Every numeric value on the public API is native bigint. Errors are thrown as POSBridgeError (extends VError) carrying a discriminator code — switch on error.code instead of parsing message strings. Contract addresses are fetched dynamically from the published address index with a 1-hour stale-while-revalidate cache, so long-running services pick up Polygon contract redeployments without restart. The BaseToken → POSToken → ERC20 inheritance chain is gone, replaced by composition over two internal services. The lazy ITransactionWriteResult shape is replaced by TxResult = { hash, confirmed() } — await write(...) resolves on broadcast, await result.confirmed() waits for the receipt.
- Package name:
@maticnetwork/maticjs→@polygonlabs/pos-sdk. The*-web3and*-etherscompanion packages no longer exist; choose one ofviem,ethers ^5.6.0, orethers ^6as a peer. - Plugin removal + per-library adapter factories:
use(Plugin)is gone. Import the factory for your library from its subpath and pass the result asparent/child:import { viemAdapter } from '@polygonlabs/pos-sdk/viem'thenPOSClient.init({ parent: viemAdapter({ public, wallet }), child: viemAdapter({ ... }) }). LikewiseethersV5Adapterfrom/ethers-v5andethersV6Adapterfrom/ethers-v6. viem and ethers are fully optional peers — importing the SDK never references a library you didn't install. - bigint everywhere: drop
BN.from/BigNumber.fromat consumer call sites. Use123nliterals orBigInt(...)from a string. - Method renames on the token classes:
withdrawStart→startWithdrawwithdrawExit→completeWithdrawwithdrawExitFaster→completeWithdrawFastetheriumSha3→soliditySha3(orAdapter.keccak256for plain bytes)
parent/childnamespaces replace theisParent: booleanparameter —pos.parent.erc20(addr).deposit(...)instead ofpos.erc20(addr, true).deposit(...).- ETH deposits hoisted to top-level:
pos.depositEther(amount)andpos.depositEtherWithGas(amount)(ETH has no token contract, so they don't fit onparent.erc20(addr)). - TxResult shape:
const result = await pos.parent.erc20(addr).approve(amount); const receipt = await result.confirmed();. The legacyresult.getTransactionHash()/result.getReceipt()lazy methods are gone. - Dropped configuration fields:
version,log: boolean,option.returnTransaction,resolution(UnstoppableDomains). - Fast exits:
setProofApi(url)global mutation → optionalproofGenerationApiUrlonPOSClient.init(no default — fast exits stay opt-in; unset throwsPROOF_API_NOT_SETand payloads build locally). - Dropped Adapter methods:
signTypedData(was unused). - Errors: replace
try/catch (err) { if (err.message.includes('checkpointed')) ... }withtry/catch (err) { if (err instanceof POSBridgeError) switch (err.code) { case 'BURN_TX_NOT_CHECKPOINTED': ... } }.
The bridge protocol itself — predicates, the RootChainManager, exit proofs, the proof API — is unchanged. Existing checkpoints, bridge state, and contract addresses are fully compatible. The migration is entirely on the SDK side.
- Unsigned transactions via
prepareXxx. Every public write has a siblingprepareXxxmethod (prepareApprove,prepareDeposit,prepareCompleteWithdraw,prepareDepositEther, etc.) that returns{ to, data, value? }instead of broadcasting. Use this for Safe / Sequence / account-abstraction bundlers, batched multicall flows, pre-flight inspection, or any path where the SDK should encode the bridge call but a different signer should send it. - Bridge helpers exposed on
POSClient. Direct access topos.buildExitPayload(burnTx, sig, fast?),pos.buildExitPayloads(...)(all matching logs),pos.buildExitPayloadOnIndex(...),pos.isCheckpointed(burnTx),pos.isDeposited(depositTx)(state-sync deposit confirmation),pos.isWithdrawn(burnTx, sig),pos.isWithdrawnOnIndex(...),pos.getBlockProof(blockNum, range),pos.getPredicateAddress(token). Restores the non-token capabilities (buildMultiplePayloadsForExit,isDeposited) and the flatpos.client.exitUtil.Xaccess that services likeproof-generation-apirelied on for sync block events, custom bridge events, and plasma exits. - Reorg-safe checkpoint reads. Root-block / checkpoint reads default to the
'safe'block tag (tunable viarootChainDefaultBlock), avoiding the reorg race where a proof is built against an un-finalised header. POSBridgeErrorextendsVError. A TypeScript-first, browser-friendly port of Joyent's canonical Nodeverrorlibrary — samefindCauseByName/findCauseByType/info/fullStackhelpers, zero runtime dependencies. Structuredinfois an own enumerable property so any logger that serializes own properties on Error instances (pino, winston, Sentry, custom) picks it up. The constructor's third arg is renamedcontext→infoto match the VError convention; positional call sites keep working unchanged.
See MIGRATION.md for the full upgrade walkthrough with before/after code blocks, including a comprehensive replacement table for every removed API (signTypedData, etheriumSha3, encode, sendRPCRequest, etc.).