diff --git a/docs/guides/developer-tools/graphql-api/migration-guide.mdx b/docs/guides/developer-tools/graphql-api/migration-guide.mdx index 2c58452..c17dd9a 100644 --- a/docs/guides/developer-tools/graphql-api/migration-guide.mdx +++ b/docs/guides/developer-tools/graphql-api/migration-guide.mdx @@ -3,309 +3,123 @@ id: migration-guide title: Migration Guide sidebar_label: Migration Guide sidebar_position: 5 -description: Guide to migrating from v1.0 to v1.5 of the Intuition GraphQL API +description: Migrating GraphQL from v1.5 to v2.0 --- -# v1.5 Migration Guide +# Migrating GraphQL from v1.5 to v2.0 -**Abstract**: The Intuition API is being updated to support exciting new features, and developers using the API will need to make adjustments to their queries to continue using it. This document serves as a comprehensive guide for that process. - -## Current Status - -The Base Sepolia and Base Mainnet 1.5 backend is already live and accessible: +## Overview | Environment | Endpoint | |-------------|----------| -| **Base Sepolia** | `https://prod.base-sepolia-v-1-5.intuition.sh/v1/graphql` | -| **Base Mainnet** | `https://prod.base-mainnet-v-1-0.intuition.sh/v1/graphql` | - -## โœจ New Features - -### Core Enhancements - -| Feature | Description | -|---------|-------------| -| **๐Ÿฆ Bonding Curve Vaults** | New vault types with dynamic pricing models | -| **๐Ÿ“‹ Bonding Curve Registry** | Centralized registry for curve management | -| **Improved Batch Methods** | Enhanced batch operations for better performance | -| **โœ… Improved Approval Methods** | Better deposit/redeem and batch deposit/redeem approvals | -| **Enhanced Events & Data** | Price history, P&L, total market cap for individual vaults | -| **Introduction of 'Terms'** | New concept for atoms and triples semantics | -| **Multiple Vaults per Term** | Pro Rata Vault (1.0) + Bonding Curve Vaults | -| **๐Ÿ”’ Security Improvements** | Updates from Consensys Diligence audit | - -### What Changed Conceptually - -We have introduced the idea of a **"Term"**. A "Term" refers to an Atom, Triple or Counter-triple as a *concept*. The URI or Data of an Atom, or the Atom IDs contained within a Triple or Counter-Triple belong to the "Term". Any economic state associated with the "Term" is stored in multiple "Vaults" associated with that Term. - -#### ๐Ÿ”— **Term Structure** - -```text -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ TERM โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ ๐Ÿงฉ Atom/Triple/Counter-triple โ”‚ -โ”‚ ๐Ÿฆ Multiple Vaults โ”‚ -โ”‚ ๐Ÿ“Š Total Market Cap โ”‚ -โ”‚ ๐Ÿ’ฐ Economic State โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -#### Market Cap Calculation - -Each Term has a `total_market_cap` value which is an aggregate market cap of all its constituent Vaults. This is *theoretical* - it represents the arithmetic product of `totalShares` and `currentSharePrice`, not actual `totalAssets`. - -> โš ๏ธ **Note**: The `total_market_cap` will generally be larger than actual `totalAssets` due to slippage effects during liquidation. - -## ๐Ÿ”„ Migration Checklist - -### ๐Ÿ“‹ **Core Schema Changes** - -Update these field names in your GraphQL queries: - -| Old Field | New Field | Type Change | -|-----------|-----------|-------------| -| `id` | `term_id` | Primary identifier | -| `vault` | `term` | Nested object (when referring to concept) | -| `vault` | `vaults(where: { curve_id: {_eq: "[X]" } })` | Specific curve vault | -| `total_shares` | `total_market_cap` | In term object or specific vault | -| `block_timestamp` | `created_at` | `TIMESTAMP WITH TIME ZONE NOT NULL` | - -### โฐ **Timestamp Field Updates** - -All timestamp fields have been updated: - -| Entity | Old Field | New Field | Additional | -|--------|-----------|-----------|------------| -| **Atom** | `block_timestamp` | `created_at` | + `updated_at` | -| **Position** | `block_timestamp` | `created_at` | + `updated_at` | -| **Vault** | `block_timestamp` | `created_at` | + `updated_at` | -| **Triple** | `block_timestamp` | `created_at` | - | -| **Signal** | `block_timestamp` | `created_at` | - | -| **Deposit** | `block_timestamp` | `created_at` | - | -| **FeeTransfer** | `block_timestamp` | `created_at` | - | -| **Redemption** | `block_timestamp` | `created_at` | - | - -### ๐Ÿฆ **Vault Access Changes** - -Instead of accessing a single vault, you now need to specify the curve: - -```graphql -# OLD: Single vault access -vault(where: { id: { _eq: "42" } }) { - total_shares - total_assets -} - -# NEW: Curve-specific vault access -vaults(where: { - curve_id: { _eq: "1" }, - term_id: { _eq: "42" } -}) { - total_shares - total_assets - total_market_cap -} -``` - -## ๐Ÿ’ป Migration Examples - -### ๐Ÿ“ **Example 1: Get Entries Query** - -```graphql -# OLD SCHEMA -query GetEntries($isTypeTypeId: numeric!, $entryTypeId: numeric!, $limit: Int!, $offset: Int!) { - triples { - subject { - id - value { - thing { ... } - } - vault { - total_shares - } - } - } -} +| **Intuition Testnet** | `https://testnet.intuition.sh/v1/graphql` | -# NEW SCHEMA -query GetEntries($isTypeTypeId: numeric!, $entryTypeId: numeric!, $limit: Int!, $offset: Int!) { - triples { - subject { - term_id - atom_value { - thing { ... } - } - term { - total_market_cap - } - } - } -} -``` - -### ๐Ÿ” **Example 2: Get Entry Query** - -```graphql -# OLD SCHEMA -query GetEntry($id: numeric!, $typePredicateId: numeric!, $entryTypeId: numeric!) { - atom(id: $id) { - id - value { ... } - } -} - -# NEW SCHEMA -query GetEntry($term_id: numeric!, $typePredicateId: numeric!, $entryTypeId: numeric!) { - atom(term_id: $term_id) { - term_id - atom_value { ... } - } -} -``` -### ๐Ÿ”Ž **Example 3: Search Entries Query** +## โš ๏ธ Breaking Changes -```graphql -# OLD SCHEMA -query SearchEntries { - atoms(where: { - value: { thing: { ... } } - }) { - id - value { ... } - vault { total_shares } - } -} +### 1. ID Field Type Changes: Numeric โ†’ String -# NEW SCHEMA -query SearchEntries { - atoms(where: { - atom_value: { thing: { ... } } - }) { - term_id - atom_value { ... } - term { total_market_cap } - } -} -``` +**CRITICAL IMPACT** - All existing queries and mutations using these fields will break. -### ๐Ÿ“Š **Example 4: Order By Changes** +#### Core Entity ID Changes -```graphql -# OLD -order_by: [{ vault: { total_shares: desc } }] +| Entity | Field | Old Type | New Type | +| ------------- | ----------------- | ---------- | --------- | +| `accounts` | `atom_id` | `numeric` | `String` | +| `atoms` | `term_id` | `numeric!` | `String!` | +| `atoms` | `value_id` | `numeric` | `String` | +| `atom_values` | `id` | `numeric!` | `String!` | +| `atom_values` | `book_id` | `numeric` | `String` | +| `atom_values` | `byte_object_id` | `numeric` | `String` | +| `atom_values` | `json_object_id` | `numeric` | `String` | +| `atom_values` | `organization_id` | `numeric` | `String` | +| `atom_values` | `person_id` | `numeric` | `String` | +| `atom_values` | `text_object_id` | `numeric` | `String` | +| `atom_values` | `thing_id` | `numeric` | `String` | +| `vaults` | `term_id` | `numeric!` | `String!` | -# NEW -order_by: [{ subject: { term: { total_market_cap: desc } }}] -``` +#### Entity Primary ID Changes -## ๐Ÿฆ Bonding Curves +All primary `id` fields changed from `numeric!` to `String!`: -### ๐Ÿ“ˆ **Offset Square Root Curve 2,5e35** +- `books` +- `byte_object` +- `caip10` +- `json_objects` +- `organizations` +- `persons` +- `text_objects` +- `things` +- `terms` -Our first recommended curve follows a "square root" price function pattern with an offset to make the early portion less dramatic: +### 2. Removed Aggregate Fields -| Feature | Description | -|---------|-------------| -| **๐Ÿ“Š Price Function** | Square root pattern with offset | -| **๐ŸŽฏ Early Advantage** | Earliest stakers get most advantageous share price | -| **๐Ÿ“ˆ Growth Pattern** | Share price increases supralinearly (gently) | -| **๐Ÿ’ฐ Profit Potential** | Users can redeem at higher prices as share price increases | +**MEDIUM IMPACT** - Statistical queries will break for entities with String IDs. -### ๐Ÿ”„ **Comparison: Pro-Rata vs Bonding Curve** +Removed aggregate field types (no longer available for statistical operations): -| Aspect | Pro-Rata (1.0) | Bonding Curve (1.5) | -|--------|----------------|---------------------| -| **Share Price** | Always "1" (with fee adjustments) | Dynamic based on curve function | -| **Profit Potential** | Limited (high activity required) | Significant upside potential | -| **Risk Level** | Low (minimal downside) | Higher (price can diminish) | -| **Economic Activity** | High activity needed for profit | Profitable with moderate activity | +- `*_avg_fields` for: accounts, atom_values, books, byte_object, json_objects, organizations, persons, text_objects, things +- `*_stddev_fields`, `*_stddev_pop_fields`, `*_stddev_samp_fields` +- `*_sum_fields`, `*_var_pop_fields`, `*_var_samp_fields`, `*_variance_fields` -## ๐Ÿ”ง Smart Contract Updates +## ๐Ÿ†• New Features -### ๐Ÿ“‹ **New Bonding Curve Mutators** +### 1. New Optional Fields -```solidity -/// @notice deposit eth into an atom vault and grant ownership of 'shares' to 'receiver' -function depositAtomCurve(address receiver, uint256 atomId, uint256 curveId) external payable returns (uint256); +#### atom_values -/// @notice redeem shares from an atom vault for assets -function redeemAtomCurve(uint256 percentage, address receiver, uint256 atomId, uint256 curveId) external returns (uint256); -``` +- `caip10_id: String` - Link to CAIP-10 identifiers -### ๐Ÿ” **New Bonding Curve Accessors** +### 2. New Entity Types -```solidity -/// @notice returns current share price for a specific curve -function currentSharePriceCurve(uint256 vaultId, uint256 curveId) external view returns (uint256); +Statistics and analytics entities: -/// @notice returns max amount of shares that can be redeemed -function maxRedeemCurve(address owner, uint256 vaultId, uint256 curveId) external view returns (uint256); +- `statHours` - Hourly statistics aggregation +- `term_total_state_changes` - Term state change tracking +- `term_total_state_change_stats_daily` - Daily aggregated statistics +- `term_total_state_change_stats_hourly` - Hourly aggregated statistics +- `term_total_state_change_stats_monthly` - Monthly aggregated statistics +- `term_total_state_change_stats_weekly` - Weekly aggregated statistics -/// @notice simulates deposit effects and returns estimated shares -function previewDepositCurve(uint256 assets, uint256 vaultId, uint256 curveId) external view returns (uint256); +### 3. New Scalar Types -/// @notice simulates redemption effects and returns estimated assets -function previewRedeemCurve(uint256 shares, uint256 vaultId, uint256 curveId) external view returns (uint256); -``` +- `atom_resolving_status` - Custom scalar for atom resolution states +- `vault_type` - Custom scalar for vault type definitions -### โœ… **Updated Approval Method** +## ๐Ÿ”ง Migration Checklist -```solidity -/// @notice Set the approval type for a sender to act on behalf of the receiver -/// @param sender address to set approval for -/// @param approvalType type of approval to grant (NONE = 0, DEPOSIT = 1, REDEMPTION = 2, BOTH = 3) -function approve(address sender, ApprovalTypes approvalType) external; -``` +### Client Application Updates -### ๐Ÿ“ฆ **Batch Methods** +#### 1. Query/Mutation Updates -```solidity -/// @notice Batch create atoms and return their vault ids -function batchCreateAtom(bytes[] calldata atomUris) external payable returns (uint256[] memory); +- [ ] Update all numeric ID field references to String +- [ ] Remove or update queries using deprecated aggregate fields +- [ ] Test all existing GraphQL operations -/// @notice batch create triples and return their vault ids -function batchCreateTriple(uint256[] calldata subjectIds, uint256[] calldata predicateIds, uint256[] calldata objectIds) external payable returns (uint256[] memory); +#### 2. Code Generation Updates -/// @notice deposit eth into multiple terms and grant ownership of 'shares' to 'receiver' -function batchDeposit(address receiver, uint256[] calldata termIds, uint256[] calldata amounts) external payable returns (uint256[] memory); +- [ ] Regenerate TypeScript types +- [ ] Update GraphQL codegen configuration +- [ ] Verify generated types match new schema -/// @notice deposit eth into bonding curve vaults -function batchDepositCurve(address receiver, uint256[] calldata termIds, uint256[] calldata curveIds, uint256[] calldata amounts) external payable returns (uint256[] memory); +#### 3. Variable Updates -/// @notice redeem shares from multiple vaults -function batchRedeem(uint256 percentage, address receiver, uint256[] calldata ids) external returns (uint256[] memory); +```graphql +# OLD +query GetAtom($termId: numeric!) { + atoms(where: { term_id: { _eq: $termId } }) { + term_id + value_id + } +} -/// @notice redeem shares from bonding curve vaults -function batchRedeemCurve(uint256 percentage, address receiver, uint256[] calldata termIds, uint256[] calldata curveIds) external returns (uint256[] memory); +# NEW +query GetAtom($termId: String!) { + atoms(where: { term_id: { _eq: $termId } }) { + term_id + value_id + raw_data + resolving_status + } +} ``` - -## ๐Ÿšจ Important Notes - -### โš ๏ธ **Claims Deprecation** - -If using `claims`, it's suggested to start using `positions` instead, as the positions contain the same information and more. Claims are likely to be sunset in the near future. - -### ๐Ÿงช **Testing Environment** - -> โš ๏ธ **Caution**: The Dummy 1.5 contract does not contain the same dataset as the 1.0 contract on Base Sepolia. If your app relies on specific data, you may need to add it to the Dummy 1.5 contract for testing. - -Once the contract upgrade is completed, the 1.5 contract will have the same data set as the 1.0 version and will live at the same contract address. - -## ๏ฟฝ๏ฟฝ Endpoint Changes - -| Environment | Old Endpoint | New Endpoint | -|-------------|--------------|--------------| -| **Development** | `https://prod.base-sepolia.intuition-api.com/v1/graphql` | `https://prod.base-sepolia-v-1-5.intuition.sh/v1/graphql` | - -## ๐Ÿ“š Additional Resources - -- ๐Ÿ“– [Official v1.5 Migration Guide](https://tech.docs.intuition.systems/dev/1.5-migration) -- ๐Ÿ”— [Bonding Curve Documentation](/guides/introduction/the-economics/bonding-curves) -- ๐Ÿ› ๏ธ [GraphQL API Reference](/guides/developer-tools/graphql-api) -- ๐Ÿ’ฌ [Community Support](https://discord.gg/intuition) - ---- - -> ๐Ÿš€ **Ready to migrate?** Start with our [Quick Start Guide](/guides/quickstart) or explore the [SDK Documentation](/guides/developer-tools/sdks) to begin your v1.5 migration! \ No newline at end of file diff --git a/docs/guides/developer-tools/sdks/migration-guide.mdx b/docs/guides/developer-tools/sdks/migration-guide.mdx new file mode 100644 index 0000000..4025ccb --- /dev/null +++ b/docs/guides/developer-tools/sdks/migration-guide.mdx @@ -0,0 +1,640 @@ +--- +id: migration-guide +title: SDK migration +sidebar_label: SDK Migrtion Guide +sidebar_position: 3 +description: Migrating SDK from v1.5 to v2.0 +--- + +# Migrating SDK from v1.5 to v2.0 + +This guide helps you migrate your code from v1.x to v2.0.0-alpha of the Intuition TypeScript packages. This is a **major version update** with significant breaking changes due to the underlying contract migration from `EthMultiVault` to `MultiVault`. + +## Contract Migration Overview + +The core smart contract has been upgraded from `EthMultiVault` to `MultiVault`, introducing significant architectural changes that impact all TypeScript libraries built on top. + +### Key Contract Changes + +#### 1. **ID System Migration** + +- **EthMultiVault**: Uses `uint256` for atom/triple IDs +- **MultiVault**: Uses `bytes32` for term IDs (atoms and triples are now "terms") + +#### 2. **Terminology Changes** + +- **EthMultiVault**: Atoms and Triples as separate entities +- **MultiVault**: Unified "Terms" concept (atoms and triples are both terms) +- **EthMultiVault**: Vault IDs +- **MultiVault**: Term IDs with Curve IDs for bonding curves + +#### 3. **Bonding Curve Integration** + +- **EthMultiVault**: Limited bonding curve support +- **MultiVault**: Full bonding curve integration with curve IDs for all operations + +## Breaking Changes Overview + +### Package Version Updates + +| Package | Previous Version | New Version | +| ----------------------- | ---------------- | --------------- | +| `@0xintuition/protocol` | `1.0.0-alpha.1` | `2.0.0-alpha.2` | +| `@0xintuition/sdk` | `1.0.0-alpha.3` | `2.0.0-alpha.2` | +| `@0xintuition/graphql` | `1.0.0-alpha.3` | `2.0.0-alpha.2` | +| `@0xintuition/cli` | `0.0.2` | `2.0.0-alpha.2` | + +## 1. Contract Migration Impact + +### Contract Function Mapping + +The migration from `EthMultiVault` to `MultiVault` requires updating all contract interactions. Here's the complete function mapping: + +#### Core Creation Functions + +##### Atom Creation + +```solidity +// EthMultiVault +function createAtom(bytes atomUri) payable returns (uint256) +function batchCreateAtom(bytes[] atomUris) payable returns (uint256[]) + +// MultiVault +function createAtoms(bytes[] data, uint256[] assets) payable returns (bytes32[]) +``` + +##### Triple Creation + +```solidity +// EthMultiVault +function createTriple(uint256 subjectId, uint256 predicateId, uint256 objectId) payable returns (uint256) +function batchCreateTriple(uint256[] subjectIds, uint256[] predicateIds, uint256[] objectIds) payable returns (uint256[]) + +// MultiVault +function createTriples(bytes32[] subjectIds, bytes32[] predicateIds, bytes32[] objectIds, uint256[] assets) payable returns (bytes32[]) +``` + +#### Deposit Functions + +##### EthMultiVault + +```solidity +function depositAtom(address receiver, uint256 id) payable returns (uint256) +function depositTriple(address receiver, uint256 id) payable returns (uint256) +function batchDeposit(address receiver, uint256[] termIds, uint256[] amounts) payable returns (uint256[]) +``` + +##### MultiVault + +```solidity +function deposit(address receiver, bytes32 termId, uint256 curveId, uint256 minShares) payable returns (uint256) +function depositBatch(address receiver, bytes32[] termIds, uint256[] curveIds, uint256[] assets, uint256[] minShares) payable returns (uint256[]) +``` + +#### Redeem Functions + +##### EthMultiVault + +```solidity +function redeemAtom(uint256 shares, address receiver, uint256 id) returns (uint256) +function redeemTriple(uint256 shares, address receiver, uint256 id) returns (uint256) +function batchRedeem(uint256 percentage, address receiver, uint256[] ids) returns (uint256[]) +``` + +##### MultiVault + +```solidity +function redeem(address receiver, bytes32 termId, uint256 curveId, uint256 shares, uint256 minAssets) returns (uint256) +function redeemBatch(address receiver, bytes32[] termIds, uint256[] curveIds, uint256[] shares, uint256[] minAssets) returns (uint256[]) +``` + +### Contract Address Changes: `EthMultiVault` โ†’ `MultiVault` + +**Before:** + +```typescript +import { EthMultiVaultAbi } from '@0xintuition/protocol' +import { getEthMultiVaultAddress } from '@0xintuition/sdk' + +const address = getEthMultiVaultAddress(chainId) +``` + +**After:** + +```typescript +import { intuitionTestnet, MultiVaultAbi } from '@0xintuition/protocol' +import { getMultiVaultAddressFromChainId } from '@0xintuition/sdk' + +const address = getMultiVaultAddressFromChainId(intuitionTestnet.id) +``` + +### Contract Event Changes + +#### EthMultiVault Events + +```solidity +event AtomCreated(address indexed creator, address indexed atomWallet, bytes atomData, uint256 vaultId) +event TripleCreated(address indexed creator, uint256 subjectId, uint256 predicateId, uint256 objectId, uint256 vaultId) +``` + +#### MultiVault Events + +```solidity +event AtomCreated(address indexed creator, bytes32 indexed termId, bytes atomData, address atomWallet) +event TripleCreated(address indexed creator, bytes32 indexed termId, bytes32 subjectId, bytes32 predicateId, bytes32 objectId) +``` + +### Data Structure Migration + +#### ID Handling Update + +```typescript +// Before (EthMultiVault) +const atomId: bigint = 123n; +const tripleId: bigint = 456n; + +// After (MultiVault) +const atomId: `0x${string}` = "0x1234..."; // 32-byte hash +const tripleId: `0x${string}` = "0x5678..."; // 32-byte hash +``` + +#### Query Functions + +```solidity +// EthMultiVault +function atoms(uint256 atomId) view returns (bytes) +function getTripleAtoms(uint256 id) view returns (uint256, uint256, uint256) + +// MultiVault +function atom(bytes32 atomId) view returns (bytes) +function getAtom(bytes32 atomId) view returns (bytes) +function triple(bytes32 tripleId) view returns (bytes32, bytes32, bytes32) +function getTriple(bytes32 tripleId) view returns (bytes32, bytes32, bytes32) +``` + +#### Share and Asset Conversions + +```solidity +// EthMultiVault +function convertToShares(uint256 assets, uint256 id) view returns (uint256) +function convertToAssets(uint256 shares, uint256 id) view returns (uint256) + +// MultiVault +function convertToShares(bytes32 termId, uint256 curveId, uint256 assets) view returns (uint256) +function convertToAssets(bytes32 termId, uint256 curveId, uint256 shares) view returns (uint256) +``` + +### New MultiVault Features + +#### 1. **Utilization Tracking** + +```typescript +const userUtilization = await multiVault.getUserUtilizationForEpoch( + userAddress, + epoch, +) +const totalUtilization = await multiVault.getTotalUtilizationForEpoch(epoch) +``` + +#### 2. **Epoch System** + +```typescript +const currentEpoch = await multiVault.currentEpoch() +const lastActiveEpoch = await multiVault.lastActiveEpoch(userAddress) +``` + +#### 3. **Enhanced Fee Management** + +```typescript +// Atom wallet deposit fees +const accumulatedFees = + await multiVault.accumulatedAtomWalletDepositFees(atomWallet) +await multiVault.claimAtomWalletDepositFees(termId) + +// Protocol fees by epoch +const protocolFees = await multiVault.accumulatedProtocolFees(epoch) +``` + +#### 4. **Improved Preview Functions** + +```typescript +// Preview with different scenarios +const [shares, assetsAfterFees] = await multiVault.previewDeposit(termId, curveId, assets); +const [shares, assetsAfterFixedFees, assetsAfterFees] = await multiVault.previewAtomCreate(termId, curveId, assets); +``` + +## 2. TypeScript Library Changes + +### Protocol Package (`@0xintuition/protocol`) + +#### Atom Creation: Singular โ†’ Plural + +**Before:** + +```typescript +import { + createAtom, + createAtomCalculateBaseCost, + createAtomEncode, +} from '@0xintuition/protocol' + +// Single atom creation +await createAtom(config, { args: [atomUri], value }) + +// Encoding +const encodedData = createAtomEncode(atomUri) + +// Cost calculation +const cost = await createAtomCalculateBaseCost(config) +``` + +**After:** + +```typescript +import { + createAtoms, + createAtomsEncode, + getAtomCost, +} from '@0xintuition/protocol' + +// Atoms creation (supports single or multiple) +await createAtoms(config, { + args: [ + [atomUri1, atomUri2], + [assets1, assets2], + ], + value, +}) + +// Encoding +const encodedData = createAtomsEncode([atomUri1, atomUri2], [assets1, assets2]) + +// Cost calculation +const cost = await getAtomCost(config) +``` + +#### Triple Creation: Singular โ†’ Plural + +**Before:** + +```typescript +import { + createTriple, + createTripleCalculateBaseCost, + createTripleEncode, +} from '@0xintuition/protocol' + +await createTriple(config, { + args: [subjectId, predicateId, objectId], + value, +}) + +const encodedData = createTripleEncode(subjectId, predicateId, objectId) +const cost = await createTripleCalculateBaseCost(config) +``` + +**After:** + +```typescript +import { + createTriples, + createTriplesEncode, + getTripleCost, +} from '@0xintuition/protocol' + +await createTriples(config, { + args: [ + [subjectId1, subjectId2], + [predicateId1, predicateId2], + [objectId1, objectId2], + [assets1, assets2], + ], + value, +}) + +const encodedData = createTriplesEncode( + [subjectId1, subjectId2], + [predicateId1, predicateId2], + [objectId1, objectId2], + [assets1, assets2], +) + +const cost = await getTripleCost(config) +``` + +#### Deposit and Redeem Simplification + +**Before:** + +```typescript +import { + depositAtom, + depositAtomEncode, + depositTriple, + depositTripleEncode, + redeemAtom, + redeemAtomEncode, + redeemTriple, + redeemTripleEncode, +} from '@0xintuition/protocol' + +// Separate functions for atoms and triples +await depositAtom(config, { args: [receiver, atomId], value }) +await depositTriple(config, { args: [receiver, tripleId], value }) +await redeemAtom(config, { args: [shares, receiver, atomId] }) +await redeemTriple(config, { args: [shares, receiver, tripleId] }) +``` + +**After:** + +```typescript +import { + deposit, + depositEncode, + redeem, + redeemEncode, +} from '@0xintuition/protocol' + +// Unified functions for any vault (atom or triple) +await deposit(config, { + args: [receiver, termId, curveId, assets, minShares], + value, +}) +await redeem(config, { args: [receiver, termId, cirveId, shares, minAssets] }) + +// Unified encoding +const depositData = depositEncode(receiver, vaultId) +const redeemData = redeemEncode(shares, receiver, vaultId) +``` + +#### Batch Operations Renamed + +**Before:** + +```typescript +import { + batchCreateAtom, + batchCreateTriple, + batchDepositCurve, + batchRedeemCurve, +} from '@0xintuition/protocol' +``` + +**After:** + +```typescript +import { + createAtoms, // Replaces batchCreateAtom + createTriples, // Replaces batchCreateTriple + depositBatch, // Replaces batchDepositCurve + redeemBatch, // Replaces batchRedeemCurve +} from '@0xintuition/protocol' +``` + +#### Multicall Function Name + +**Before:** + +```typescript +import { multiCallIntuitionConfigs } from '@0xintuition/protocol' + +const config = await multiCallIntuitionConfigs({ address, publicClient }) +``` + +**After:** + +```typescript +import { multicallIntuitionConfig } from '@0xintuition/protocol' + +const config = await multicallIntuitionConfig({ address, publicClient }) +``` + +#### Removed EthMultiVault API + +**Before:** + +```typescript +import { EthMultiVault } from '@0xintuition/protocol' + +const ethMultiVault = new EthMultiVault({ publicClient, walletClient }) +const result = await ethMultiVault.createAtom('hello') +``` + +**After:** + +```typescript +import { + getMultiVaultAddressFromChainId, + intuitionTestnet, + MultiVaultAbi, +} from '@0xintuition/protocol' + +import { getContract } from 'viem' + +const multiVault = getContract({ + abi: MultiVaultAbi, + address: getMultiVaultAddressFromChainId(intuitionTestnet.id), + client: { + public: publicClient, + wallet: walletClient, + }, +}) + +const atomCost = await multiVault.read.getAtomCost() +const result = await multiVault.createAtoms([['hello'], [atomCost]], { + value: atomCost, +}) +``` + +### Bonding Curve Integration + +The new `MultiVault` contract requires curve IDs for all operations: + +```typescript +// MultiVault requires curve ID for all operations +const defaultCurveId = await multiVault.getBondingCurveConfig().defaultCurveId + +// Use in all deposit/redeem operations +await multiVault.deposit(receiver, termId, defaultCurveId, minShares, { + value: assets, +}) +``` + +### Migration Steps + +#### Step 1: Update Function Calls + +##### Creating Atoms + +```typescript +// Before +const atomId = await ethMultiVault.createAtom(atomData, { value: fee }); + +// After +const atomIds = await multiVault.createAtoms([atomData], [assets], { value: totalValue }); +const atomId = atomIds[0]; +``` + +##### Depositing + +```typescript +// Before +const shares = await ethMultiVault.depositAtom(receiver, atomId, { value: assets }); + +// After +const shares = await multiVault.deposit(receiver, termId, curveId, minShares, { value: assets }); +``` + +##### Redeeming + +```typescript +// Before +const assets = await ethMultiVault.redeemAtom(shares, receiver, atomId); + +// After +const assets = await multiVault.redeem(receiver, termId, curveId, shares, minAssets); +``` + +## 3. SDK Package Changes (`@0xintuition/sdk`) + +### API Function Renaming + +**Before:** + +```typescript +import { getAtom, getTriple } from '@0xintuition/sdk' + +const atomData = await getAtom('124862') +const tripleData = await getTriple('54670') +``` + +**After:** + +```typescript +import { getAtomDetails, getTripleDetails } from '@0xintuition/sdk' + +const atomData = await getAtomDetails( + '0x57d94c116a33bb460428eced262b7ae2ec6f865e7aceef6357cec3d034e8ea21', +) +const tripleData = await getTripleDetails( + '0x4957d3f442acc301ad71e73f26efd6af78647f57dacf2b3a686d91fa773fe0b6', +) +``` + +### Triple Creation Parameter Changes + +**Before:** + +```typescript +import { createTripleStatement } from '@0xintuition/sdk' + +const triple = await createTripleStatement(config, { + args: [subjectVaultId, predicateVaultId, objectVaultId], + depositAmount: 1000000000000000000n, // Optional +}) +``` + +**After:** + +```typescript +import { createTripleStatement } from '@0xintuition/sdk' + +const triple = await createTripleStatement(config, { + args: [ + [subjectVaultId], + [predicateVaultId], + [objectVaultId], + [1000000000000000000n], + ], + value: 1000000000000000000n, // Required +}) +``` + +## 4. Configuration Changes + +### EthMultiVault Config + +```solidity +struct GeneralConfig { + address admin; + address protocolMultisig; + uint256 feeDenominator; + uint256 minDeposit; + uint256 minShare; + uint256 atomUriMaxLength; + uint256 decimalPrecision; + uint256 minDelay; +} +``` + +### MultiVault Config + +```solidity +struct GeneralConfig { + address admin; + address protocolMultisig; + uint256 feeDenominator; + address trustBonding; // New + uint256 minDeposit; + uint256 minShare; + uint256 atomDataMaxLength; // Renamed + uint256 decimalPrecision; + // minDelay removed +} +``` + +## 5. Removed Functions + +The following functions have been removed and replaced: + +### Protocol Package + +- `createAtom` โ†’ `createAtoms` +- `createTriple` โ†’ `createTriples` +- `batchCreateAtom` โ†’ `createAtoms` +- `batchCreateTriple` โ†’ `createTriples` +- `depositAtom` / `depositTriple` โ†’ `deposit` +- `redeemAtom` / `redeemTriple` โ†’ `redeem` +- `createAtomCalculateBaseCost` โ†’ `getAtomCost` +- `createTripleCalculateBaseCost` โ†’ `getTripleCost` +- All curve-specific functions โ†’ `depositBatch` / `redeemBatch` +- `atoms-by-hash.ts` file completely removed + +### SDK Package + +- `createThing` โ†’ `createAtomFromThing` +- `createEthereumAccount` โ†’ `createAtomFromEthereumAccount` +- `getEthMultiVaultAddress` โ†’ `getMultiVaultAddressFromChainId` +- `getAtom` โ†’ `getAtomDetails` +- `getTriple` โ†’ `getTripleDetails` + +## 6. Breaking Changes Summary + +1. **All IDs changed from `uint256` to `bytes32`** +2. **Curve ID parameter required for most operations** +3. **Batch functions have different signatures** +4. **Event structures updated** +5. **Some functions renamed or merged** +6. **New slippage protection with `minShares`/`minAssets` parameters** + +## 7. Best Practices + +1. **Always use the default curve ID** unless you have specific bonding curve requirements +2. **Implement proper slippage protection** with min/max parameters +3. **Handle the new epoch system** for utilization tracking +4. **Update your event listeners** to match new event structures +5. **Use preview functions** to estimate outcomes before transactions + +## ๐Ÿ“ Summary + +This major version update consolidates and simplifies the API while adding new functionality. The main changes are: + +- **Contract Migration**: `EthMultiVault` โ†’ `MultiVault` with architectural improvements +- **ID System**: Changed from `uint256` to `bytes32` for all term identifiers +- **Bonding Curves**: Full integration requiring curve IDs for all operations +- **Singular โ†’ Plural**: Functions now support batch operations by default +- **Unified APIs**: Simplified deposit/redeem functions for all vault types +- **Enhanced Features**: New utilization tracking, epoch system, and preview functions +- **Event Updates**: Improved event parsing with new event structures + +Take your time with the migration and test thoroughly. The new API is more powerful and consistent, providing a better developer experience. diff --git a/docusaurus.config.js b/docusaurus.config.js index 789e12f..c7cfc0c 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -140,8 +140,8 @@ const config = { ({ colorMode: { defaultMode: 'light', - disableSwitch: true, - respectPrefersColorScheme: false, + disableSwitch: false, + respectPrefersColorScheme: true, }, docs: { sidebar: { diff --git a/sidebars.js b/sidebars.js index 9c4cf54..bb28d89 100644 --- a/sidebars.js +++ b/sidebars.js @@ -36,6 +36,7 @@ module.exports = { items: [ 'developer-tools/sdks/overview', 'developer-tools/sdks/boilerplate-project', + 'developer-tools/sdks/migration-guide', ], }, {