From 26d5e3073835dc74a96f4699768ca61dd4927dbb Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Fri, 13 Dec 2024 21:27:07 -0500 Subject: [PATCH 1/4] sdk: add decodeTransactionEvents Signed-off-by: Andrew Richardson --- example/bond/package-lock.json | 2 +- example/zeto/package-lock.json | 2 +- sdk/typescript/src/interfaces/domains/pente.ts | 2 +- sdk/typescript/src/interfaces/transaction.ts | 11 +++++++++++ sdk/typescript/src/paladin.ts | 15 ++++++++++++++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/example/bond/package-lock.json b/example/bond/package-lock.json index a1e498c97..69cee94a2 100644 --- a/example/bond/package-lock.json +++ b/example/bond/package-lock.json @@ -20,7 +20,7 @@ }, "../../sdk/typescript": { "name": "@lfdecentralizedtrust-labs/paladin-sdk", - "version": "0.0.6-alpha.1", + "version": "0.0.6-alpha.2", "license": "Apache-2.0", "dependencies": { "axios": "^1.7.7", diff --git a/example/zeto/package-lock.json b/example/zeto/package-lock.json index ee01375a5..d60093b3a 100644 --- a/example/zeto/package-lock.json +++ b/example/zeto/package-lock.json @@ -20,7 +20,7 @@ }, "../../sdk/typescript": { "name": "@lfdecentralizedtrust-labs/paladin-sdk", - "version": "0.0.6-alpha.1", + "version": "0.0.6-alpha.2", "license": "Apache-2.0", "dependencies": { "axios": "^1.7.7", diff --git a/sdk/typescript/src/interfaces/domains/pente.ts b/sdk/typescript/src/interfaces/domains/pente.ts index 50b65480b..97717adf5 100644 --- a/sdk/typescript/src/interfaces/domains/pente.ts +++ b/sdk/typescript/src/interfaces/domains/pente.ts @@ -7,5 +7,5 @@ export interface IGroupInfo { export interface IGroupInfoUnresolved { salt: string; - members: PaladinVerifier[]; + members: (string | PaladinVerifier)[]; } diff --git a/sdk/typescript/src/interfaces/transaction.ts b/sdk/typescript/src/interfaces/transaction.ts index e8c78a9f9..efa17819c 100644 --- a/sdk/typescript/src/interfaces/transaction.ts +++ b/sdk/typescript/src/interfaces/transaction.ts @@ -105,3 +105,14 @@ export interface IDecodedEvent { data: any; summary: string; // errors only } + +export interface IEventWithData { + blockNumber: number; + transactionIndex: number; + logIndex: number; + transactionHash: string; + signature: string; + soliditySignature: string; + address: string; + data: string; +} diff --git a/sdk/typescript/src/paladin.ts b/sdk/typescript/src/paladin.ts index 75b2d869f..55e250374 100644 --- a/sdk/typescript/src/paladin.ts +++ b/sdk/typescript/src/paladin.ts @@ -14,9 +14,10 @@ import { ITransactionReceipt, ITransactionStates, IDecodedEvent, + IEventWithData, } from "./interfaces/transaction"; import { Algorithms, Verifiers } from "./interfaces"; -import { ethers } from "ethers"; +import { ethers, InterfaceAbi } from "ethers"; import { PaladinVerifier } from "./verifier"; const POLL_INTERVAL_MS = 100; @@ -216,4 +217,16 @@ export default class PaladinClient { throw err; } } + + async decodeTransactionEvents( + transactionHash: string, + abi: InterfaceAbi, + resultFormat: string + ) { + const res = await this.post>( + "bidx_decodeTransactionEvents", + [transactionHash, abi, resultFormat] + ); + return res.data; + } } From 0b79625c42da2e2b4b4de8fc8c6198df2a189dcb Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Mon, 16 Dec 2024 12:44:36 -0500 Subject: [PATCH 2/4] sdk: fix decodeTransactionEvents Signed-off-by: Andrew Richardson --- sdk/typescript/src/interfaces/transaction.ts | 2 +- sdk/typescript/src/paladin.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/typescript/src/interfaces/transaction.ts b/sdk/typescript/src/interfaces/transaction.ts index efa17819c..2f9780635 100644 --- a/sdk/typescript/src/interfaces/transaction.ts +++ b/sdk/typescript/src/interfaces/transaction.ts @@ -114,5 +114,5 @@ export interface IEventWithData { signature: string; soliditySignature: string; address: string; - data: string; + data: any; } diff --git a/sdk/typescript/src/paladin.ts b/sdk/typescript/src/paladin.ts index 55e250374..248f9b365 100644 --- a/sdk/typescript/src/paladin.ts +++ b/sdk/typescript/src/paladin.ts @@ -227,6 +227,6 @@ export default class PaladinClient { "bidx_decodeTransactionEvents", [transactionHash, abi, resultFormat] ); - return res.data; + return res.data.result; } } From 091d3621ee2f0161cf55938b7dd4ce8a0a06ff36 Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Mon, 16 Dec 2024 12:45:19 -0500 Subject: [PATCH 3/4] Use Clones in AtomFactory Signed-off-by: Andrew Richardson --- solidity/contracts/shared/Atom.sol | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/solidity/contracts/shared/Atom.sol b/solidity/contracts/shared/Atom.sol index 801863d00..2994fd320 100644 --- a/solidity/contracts/shared/Atom.sol +++ b/solidity/contracts/shared/Atom.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.20; -import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; +import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol"; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; contract Atom is Initializable { @@ -63,26 +63,16 @@ contract Atom is Initializable { contract AtomFactory { address public immutable logic; - address public lastDeploy; // TODO: remove and listen to AtomDeployed event AtomDeployed(address addr); - // Must match the signature initialize(Atom.Operation[]) - string private constant INIT_SIGNATURE = "initialize((address,bytes)[])"; - constructor() { logic = address(new Atom()); } function create(Atom.Operation[] calldata operations) public { - bytes memory _initializationCalldata = abi.encodeWithSignature( - INIT_SIGNATURE, - operations - ); - address addr = address( - new ERC1967Proxy(logic, _initializationCalldata) - ); - lastDeploy = addr; - emit AtomDeployed(addr); + address instance = Clones.clone(logic); + Atom(instance).initialize(operations); + emit AtomDeployed(instance); } } From 7a22b2b4653c4aa90ef4a7e68a7a2c19cb4637d8 Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Mon, 16 Dec 2024 12:46:23 -0500 Subject: [PATCH 4/4] example: update use of AtomDeployed event Signed-off-by: Andrew Richardson --- example/bond/src/index.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/example/bond/src/index.ts b/example/bond/src/index.ts index a1a4477aa..2b18c9bfc 100644 --- a/example/bond/src/index.ts +++ b/example/bond/src/index.ts @@ -274,16 +274,20 @@ async function main(): Promise { receipt = await bondSubscription.using(paladin2).distribute(bondCustodian); if (!checkReceipt(receipt)) return false; - // TODO: use the AtomDeployed event instead of this lookup method - const atomAddressResult = await paladin2.call({ - type: TransactionType.PUBLIC, - abi: atomFactoryJson.abi, - function: "lastDeploy", - from: bondCustodian.lookup, - to: atomFactoryAddress, - data: {}, - }); - const atomAddress = atomAddressResult["0"]; + // Extract the address of the created Atom + const events = await paladin2.decodeTransactionEvents( + receipt.transactionHash, + atomFactoryJson.abi, + "" + ); + const atomDeployedEvent = events.find( + (e) => e.soliditySignature === "event AtomDeployed(address addr)" + ); + if (atomDeployedEvent === undefined) { + logger.error("Did not find AtomDeployed event"); + return false; + } + const atomAddress = atomDeployedEvent.data.addr; logger.log("Success!"); // Approve the payment transfer