Skip to content

Commit

Permalink
Merge branch 'paladin-sdk' of https://github.com/kaleido-io/paladin i…
Browse files Browse the repository at this point in the history
…nto one-time-intents
  • Loading branch information
peterbroadhurst committed Dec 16, 2024
2 parents 020b938 + 7a22b2b commit 4a119e2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
24 changes: 14 additions & 10 deletions example/bond/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,20 @@ async function main(): Promise<boolean> {
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
Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/src/interfaces/domains/pente.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export interface IGroupInfo {

export interface IGroupInfoUnresolved {
salt: string;
members: PaladinVerifier[];
members: (string | PaladinVerifier)[];
}
11 changes: 11 additions & 0 deletions sdk/typescript/src/interfaces/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: any;
}
15 changes: 14 additions & 1 deletion sdk/typescript/src/paladin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -216,4 +217,16 @@ export default class PaladinClient {
throw err;
}
}

async decodeTransactionEvents(
transactionHash: string,
abi: InterfaceAbi,
resultFormat: string
) {
const res = await this.post<JsonRpcResult<IEventWithData[]>>(
"bidx_decodeTransactionEvents",
[transactionHash, abi, resultFormat]
);
return res.data.result;
}
}
18 changes: 4 additions & 14 deletions solidity/contracts/shared/Atom.sol
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 4a119e2

Please sign in to comment.