From fbdba960a073985a02b7e7a19670cd71dd34a591 Mon Sep 17 00:00:00 2001 From: mguleryuz Date: Tue, 16 Apr 2024 11:51:04 +0300 Subject: [PATCH] chore(release): 0.0.7-alpha.1 --- bun.lockb | Bin 159375 -> 159376 bytes package.json | 4 +- src/getWorkflow.ts | 127 +++++++++++++++++++++++++-------------------- 3 files changed, 73 insertions(+), 58 deletions(-) diff --git a/bun.lockb b/bun.lockb index bb31a5c25b46dd78291498bf19cc9abe1e339d56..718f31efa431658ed27530ed17518af3be359249 100755 GIT binary patch delta 619 zcmeCb%Q*pv^pqwv>{gv%`Z9Ti+xM{M!~e?57O@>VHRI?1kL~ZC?OBm`jUjJizz-hH z59JIDJPZsCZz~uWxPkO_AfFdVKY@y$g7UX)F63R#JNb&b#$*Q>j?Es@Eh)T)Ky^$E z3=Et=EHJrIN`10}0q11S2769NplL=xS;onM3g(=}K%NzkY@?!Er!bp)>&`>IX+;iiN@xPTAMwa{zy6OJ!BCyC87Cj zhN39zL0K`6##7s4)77^$goW`cy`Qjb`KFlv3zjk!{heng?$&lx(ZXnr^2zFJe{CL2 z*kE{rvHjrY*0~;C4x%ja=8d~|EEL&1;l|#m;C`ZU!5t!7-ynqpa%?UQRWp1C6%A<{fIqp8k*nz^xhU$v+DTFjs;h4#^wn;F#n&sG2jP} z=KFF61|9~6hBp-q4BSBa8j#Nmq#r}YPeS>dHy83Q=baqkY_Qowx+R6f0H}tEfq`N2 z1aqCq4l*2!zbA7x*mF7njWGgBF-{ItFy|}+^31?IK?`%%%|M>zWM5fp#_y9k8|^vu zDj688!Lk=M%sDfGJWDul5nOJfv^nQpAkPOZH__OfQFF6r(;q2^l0>tx|1wLXKioe3 zM@IS8$-OqhW(NahoR_`u+-vo2qee(g=0h2=`Fw}&dIu`D%XGgG3J`uf$G_a!hWno( z-wOTBt#duP93Gb(y%;9r`#7%tdergwgKaAVb*mf}FFer6x2J7WO{|2oRrl_Dg*S!F zTc;nC>TYEfYxin<-=8bWdhYd#Zs93)+j%t@e|NDN>6z=9F>L4C%-CnkxOw{A4~&x1 zu%KJJH~wv{>-?omjD~tfdcc5VxHkPFPyyrP>90Z5`{}G785^ZFfWgBB^khcyy8plU zS7(Ya#+m3D=otb7bo#=NjPc4VfC`YK$n4O5ncM8YnwS{t4E2mb2EUnJ_=!=B1;{!% z-S!jE39#5iQwoeBuu@4zh)bql`N*ilxMKRnPmJ>!zi%)6%($JA(PX>kS4QbFcA&@f TO46&QPt0W!+n$uoq{j>Zb41!w diff --git a/package.json b/package.json index cf90837..e220752 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@inverter-network/sdk", - "version": "0.0.7-alpha.0", + "version": "0.0.7-alpha.1", "description": "INVERTER typescript SDK", "main": "./dist/cjs/index.js", "module": "./dist/index.js", @@ -77,7 +77,7 @@ "abitype": "^1", "eslint": "^8", "typescript": "^5", - "viem": "2.7.6" + "viem": "^2.7.6" }, "dependencies": { "@inverter-network/abis": "0.0.7-alpha.0" diff --git a/src/getWorkflow.ts b/src/getWorkflow.ts index ac7b3a6..2412bfc 100644 --- a/src/getWorkflow.ts +++ b/src/getWorkflow.ts @@ -22,8 +22,7 @@ type WorkflowOrientation = { } export default async function getWorkflow< - // O extends WorkflowOrientation | undefined, - O extends WorkflowOrientation, + O extends WorkflowOrientation | undefined = undefined, W extends WalletClient | undefined = undefined, >({ publicClient, @@ -34,9 +33,7 @@ export default async function getWorkflow< publicClient: PublicClient walletClient?: W orchestratorAddress: Hex - // with optional workflowOrientation TODO - // workflowOrientation?: O - workflowOrientation: O + workflowOrientation?: O }) { if (!publicClient) throw new Error('Public client not initialized') @@ -77,32 +74,78 @@ export default async function getWorkflow< }) // 3. initialize modules with extras - const modules = ( - await Promise.all( - Object.values(workflowOrientation).map(async ({ name, version }) => { - const address = - await orchestrator.read.findModuleAddressInOrchestrator.run(name) + const modules = await (async () => { + // 0. Define the source data based on the optional workflowOrientation + const source = + // 1. Check if workflowOrientation is defined + !!workflowOrientation + ? // 2. If defined, map over the values and find the address of the module + await Promise.all( + Object.values(workflowOrientation).map(async (i) => ({ + ...i, + address: + await orchestrator.read.findModuleAddressInOrchestrator.run( + i.name + ), + })) + ) + : // 3. If not defined, list all modules from the orchestrator for their- + // address then get the title and version + await Promise.all( + (await orchestrator.read.listModules.run()).map(async (address) => { + const flatModule = getModule({ + publicClient, + walletClient, + address, + name: 'Module', + version: 'v1.0', + }), + name = await flatModule.read.title.run(), + [major, minor] = await flatModule.read.version.run(), + version = (() => { + const initialRes = `v${major}.${minor}` + if (initialRes.length > 4) return 'v1.0' + return initialRes + })() - return getModule({ - name, - version, - address, - publicClient, - walletClient, - extras: { - decimals: erc20Decimals, - }, - }) + return { name, version, address } + }) + ) + + console.log('SOURCE: \n', source) + // 4. Map the module array using the source data + const modulesArray = source.map(({ name, version, address }) => + getModule({ + name, + version, + address, + publicClient, + walletClient, + extras: { + decimals: erc20Decimals, + }, }) ) - ).reduce((acc: any, curr) => { - acc[curr.moduleType] = curr - return acc - }, {}) as { - [K in keyof WorkflowOrientation]: ReturnType< - typeof getModule - > - } + + console.log('MODULES ARRAY: \n', modulesArray) + // 5. Reduce the array to an object with the moduleType as key + const result = modulesArray.reduce((acc: any, curr) => { + acc[curr.moduleType] = curr + return acc + }, {}) as { + [K in keyof WorkflowOrientation]: O extends NonNullable + ? ReturnType> + : ReturnType< + typeof getModule< + WorkflowOrientation[K]['name'], + WorkflowOrientation[K]['version'], + W + > + > + } + + return result + })() // RETURN WORKFLOW CONFIG const returns = { @@ -115,31 +158,3 @@ export default async function getWorkflow< return returns } - -// with optional workflowOrientation TODO -// const addressAndVersions = (async () => { -// if (!workflowOrientation) -// return await Promise.all( -// (await orchestrator.read.listModules.run()).map(async (address) => { -// const contract = getContract({ -// client, -// address, -// abi: FlatModule_ABI, -// }) - -// const name = await contract.read.title(), -// version = await contract.read.version() - -// return { name, version, address } -// }) -// ) - -// return await Promise.all( -// Object.values(workflowOrientation).map(async ({ name, version }) => { -// const address = -// await orchestrator.read.findModuleAddressInOrchestrator.run(name) - -// return { name, version, address } -// }) -// ) -// })()