diff --git a/packages/core/src/api/joints/spore/injectLiveSporeCell.ts b/packages/core/src/api/joints/spore/injectLiveSporeCell.ts index 63a5f63..2533026 100644 --- a/packages/core/src/api/joints/spore/injectLiveSporeCell.ts +++ b/packages/core/src/api/joints/spore/injectLiveSporeCell.ts @@ -1,8 +1,14 @@ import { BIish } from '@ckb-lumos/bi'; import { PackedSince } from '@ckb-lumos/base'; -import { BI, Cell, helpers, HexString } from '@ckb-lumos/lumos'; +import { BI, Cell, helpers, HexString, Indexer, Script } from '@ckb-lumos/lumos'; import { addCellDep, parseAddress } from '@ckb-lumos/lumos/helpers'; -import { decodeContentType, isContentTypeValid, setAbsoluteCapacityMargin, setupCell } from '../../../helpers'; +import { + decodeContentType, + getCellByType, + isContentTypeValid, + setAbsoluteCapacityMargin, + setupCell, +} from '../../../helpers'; import { getSporeConfig, getSporeScript, SporeConfig } from '../../../config'; import { unpackToRawSporeData } from '../../../codec'; import { getMutantById } from '../mutant/getMutant'; @@ -68,7 +74,26 @@ export async function injectLiveSporeCell(props: { } // Add Spore script as cellDep - txSkeleton = addCellDep(txSkeleton, sporeScript.cellDep); + let sporeCelldep = sporeScript.cellDep; + if (sporeScript.behaviors?.dynamicCeldep) { + const args = sporeScript.behaviors?.dynamicCeldep; + const typeIdScript: Script = { + codeHash: '0x00000000000000000000000000000000000000000000000000545950455f4944', + hashType: 'type', + args, + }; + const scriptCell = await getCellByType({ + type: typeIdScript, + indexer: new Indexer(config.ckbIndexerUrl, config.ckbNodeUrl), + }); + if (scriptCell) { + sporeCelldep = { + outPoint: scriptCell.outPoint!, + depType: 'code', + }; + } + } + txSkeleton = addCellDep(txSkeleton, sporeCelldep); // Validate SporeData.contentType const sporeData = unpackToRawSporeData(sporeCell.data); diff --git a/packages/core/src/api/joints/spore/injectNewSporeOutput.ts b/packages/core/src/api/joints/spore/injectNewSporeOutput.ts index bae62d8..226d218 100644 --- a/packages/core/src/api/joints/spore/injectNewSporeOutput.ts +++ b/packages/core/src/api/joints/spore/injectNewSporeOutput.ts @@ -1,11 +1,11 @@ import { BIish } from '@ckb-lumos/bi'; import { Script } from '@ckb-lumos/base'; import { bytes, BytesLike } from '@ckb-lumos/codec'; -import { Address, BI, Cell, Hash, helpers, HexString, PackedSince } from '@ckb-lumos/lumos'; +import { Address, BI, Cell, Hash, helpers, HexString, Indexer, PackedSince } from '@ckb-lumos/lumos'; import { addCellDep } from '@ckb-lumos/lumos/helpers'; import { packRawSporeData } from '../../../codec'; import { getSporeConfig, getSporeScript, SporeConfig } from '../../../config'; -import { EncodableContentType, setContentTypeParameters } from '../../../helpers'; +import { EncodableContentType, getCellByType, setContentTypeParameters } from '../../../helpers'; import { correctCellMinimalCapacity, setAbsoluteCapacityMargin } from '../../../helpers'; import { composeInputLocks, composeOutputLocks, decodeContentType, isContentTypeValid } from '../../../helpers'; import { getClusterById } from '../cluster/getCluster'; @@ -223,7 +223,26 @@ export async function injectNewSporeOutput(props: { } // Add Spore relevant cellDeps - txSkeleton = addCellDep(txSkeleton, sporeScript.cellDep); + let sporeCelldep = sporeScript.cellDep; + if (sporeScript.behaviors?.dynamicCeldep) { + const args = sporeScript.behaviors?.dynamicCeldep; + const typeIdScript: Script = { + codeHash: '0x00000000000000000000000000000000000000000000000000545950455f4944', + hashType: 'type', + args, + }; + const scriptCell = await getCellByType({ + type: typeIdScript, + indexer: new Indexer(config.ckbIndexerUrl, config.ckbNodeUrl), + }); + if (scriptCell) { + sporeCelldep = { + outPoint: scriptCell.outPoint!, + depType: 'code', + }; + } + } + txSkeleton = addCellDep(txSkeleton, sporeCelldep); return { txSkeleton, diff --git a/packages/core/src/config/predefined.ts b/packages/core/src/config/predefined.ts index 6ac0c10..21f67cb 100644 --- a/packages/core/src/config/predefined.ts +++ b/packages/core/src/config/predefined.ts @@ -12,6 +12,25 @@ const TESTNET_SPORE_CONFIG: SporeConfig = { scripts: { Spore: { versions: [ + // see: https://github.com/dotbitHQ/did-contracts/blob/docs/docs/Deployed-Scripts.md#testnet + { + tags: ['v2', 'did'], + script: { + codeHash: '0x0b1f412fbae26853ff7d082d422c2bdd9e2ff94ee8aaec11240a5b34cc6e890f', + hashType: 'type', + }, + cellDep: { + outPoint: { + txHash: '0x29d0123dda05cb92452a46df609e9bd08e066d62f0c3953fe34935dc10edfdcc', + index: '0x0', + }, + depType: 'code', + }, + behaviors: { + lockProxy: true, + dynamicCeldep: '0x80f0d4bf6b3951911aa6b98cc609d477a8a10b903b35cfd528d098e95c36f680', + }, + }, { tags: ['v2', 'preview'], script: { @@ -180,6 +199,25 @@ const MAINNET_SPORE_CONFIG: SporeConfig = { scripts: { Spore: { versions: [ + // see: https://github.com/dotbitHQ/did-contracts/blob/docs/docs/Deployed-Scripts.md#mainnet + { + tags: ['v2', 'did'], + script: { + codeHash: '0xcfba73b58b6f30e70caed8a999748781b164ef9a1e218424a6fb55ebf641cb33', + hashType: 'type', + }, + cellDep: { + outPoint: { + txHash: '0x18dda0f02036305b423b85cce276a40417faed044b2ee9220284215f38734daa', + index: '0x0', + }, + depType: 'code', + }, + behaviors: { + lockProxy: true, + dynamicCeldep: '0x62312cd846659e188b05da11dc3f080b083c27371ea701d6026e11e713e0e3de', + }, + }, { tags: ['v2', 'latest'], script: { diff --git a/packages/core/src/config/types.ts b/packages/core/src/config/types.ts index 5eb75d4..8e4333c 100644 --- a/packages/core/src/config/types.ts +++ b/packages/core/src/config/types.ts @@ -2,6 +2,7 @@ import { Config } from '@ckb-lumos/config-manager'; import { CellDep } from '@ckb-lumos/base'; import { ScriptId } from '../types'; import { ClusterDataVersion } from '../codec'; +import { HexString } from '@ckb-lumos/lumos'; export interface SporeConfig { lumos: Config; @@ -35,4 +36,5 @@ export interface SporeScriptBehaviors { lockProxy?: boolean; cobuild?: boolean; clusterDataVersion?: ClusterDataVersion; + dynamicCeldep?: HexString; }