Skip to content

Commit

Permalink
feat(api): optimistic transaction results
Browse files Browse the repository at this point in the history
  • Loading branch information
hbriese committed Aug 1, 2024
1 parent 52464c0 commit f18cb99
Show file tree
Hide file tree
Showing 46 changed files with 1,070 additions and 882 deletions.
142 changes: 72 additions & 70 deletions api/dbschema/edgeql-js/__spec__.ts

Large diffs are not rendered by default.

394 changes: 208 additions & 186 deletions api/dbschema/edgeql-js/modules/default.ts

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions api/dbschema/edgeql-js/modules/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,6 @@ export type $ObjectTypeλShape = $.typeutil.flatten<$SourceλShape & Omit<$Consi
"<__type__[is Approval]": $.LinkDesc<_default.$Approval, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Proposal]": $.LinkDesc<_default.$Proposal, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Simulation]": $.LinkDesc<_default.$Simulation, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Result]": $.LinkDesc<_default.$Result, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is ReceiptResult]": $.LinkDesc<_default.$ReceiptResult, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Successful]": $.LinkDesc<_default.$Successful, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is ApproverDetails]": $.LinkDesc<_default.$ApproverDetails, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Message]": $.LinkDesc<_default.$Message, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Operation]": $.LinkDesc<_default.$Operation, $.Cardinality.Many, {}, false, false, false, false>;
Expand All @@ -713,9 +710,9 @@ export type $ObjectTypeλShape = $.typeutil.flatten<$SourceλShape & Omit<$Consi
"<__type__[is Contact]": $.LinkDesc<_default.$Contact, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is GlobalLabel]": $.LinkDesc<_default.$GlobalLabel, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Event]": $.LinkDesc<_default.$Event, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is TransferDetails]": $.LinkDesc<_default.$TransferDetails, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Transferlike]": $.LinkDesc<_default.$Transferlike, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Transfer]": $.LinkDesc<_default.$Transfer, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Contract]": $.LinkDesc<_default.$Contract, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is TransferApproval]": $.LinkDesc<_default.$TransferApproval, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Rejection]": $.LinkDesc<_default.$Rejection, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is ActionFunction]": $.LinkDesc<_default.$ActionFunction, $.Cardinality.Many, {}, false, false, false, false>;
Expand All @@ -725,12 +722,17 @@ export type $ObjectTypeλShape = $.typeutil.flatten<$SourceλShape & Omit<$Consi
"<__type__[is PolicyState]": $.LinkDesc<_default.$PolicyState, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Policy]": $.LinkDesc<_default.$Policy, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is RemovedPolicy]": $.LinkDesc<_default.$RemovedPolicy, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is SystemTx]": $.LinkDesc<_default.$SystemTx, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Failed]": $.LinkDesc<_default.$Failed, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Failure]": $.LinkDesc<_default.$Failure, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Result]": $.LinkDesc<_default.$Result, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Confirmed]": $.LinkDesc<_default.$Confirmed, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is OptimisticSuccess]": $.LinkDesc<_default.$OptimisticSuccess, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is ConfirmedFailure]": $.LinkDesc<_default.$ConfirmedFailure, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Success]": $.LinkDesc<_default.$Success, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is ConfirmedSuccess]": $.LinkDesc<_default.$ConfirmedSuccess, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Scheduled]": $.LinkDesc<_default.$Scheduled, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is PaymasterFees]": $.LinkDesc<_default.$PaymasterFees, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is SystemTx]": $.LinkDesc<_default.$SystemTx, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Function]": $.LinkDesc<_default.$Function, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__[is Contract]": $.LinkDesc<_default.$Contract, $.Cardinality.Many, {}, false, false, false, false>;
"<__type__": $.LinkDesc<$.ObjectType, $.Cardinality.Many, {}, false, false, false, false>;
"<intersection_of": $.LinkDesc<$.ObjectType, $.Cardinality.Many, {}, false, false, false, false>;
"<subject": $.LinkDesc<$.ObjectType, $.Cardinality.Many, {}, false, false, false, false>;
Expand Down
29 changes: 15 additions & 14 deletions api/dbschema/events.esdl
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
module default {
type Event {
required account: Account;
required systxHash: Bytes32;
systx: SystemTx;
systxHash: Bytes32;
result: Result;
required block: bigint { constraint min_value(0); }
required logIndex: uint32;
required timestamp: datetime { default := datetime_of_statement(); }
required internal: bool;

index on ((.account, .internal));
required internal: bool {
default := true;
rewrite insert, update using (exists __subject__.result);
};
required confirmed: bool {
default := true;
rewrite insert, update using ((__subject__.result is Confirmed) ?? true);
}

access policy members_can_select
allow select
using (is_member(.account));
}

type TransferDetails {
required account: Account;
abstract type Transferlike extending Event {
required from: Address;
required to: Address;
required tokenAddress: UAddress;
Expand All @@ -30,20 +34,17 @@ module default {
required incoming: bool;
required outgoing: bool;
required isFeeTransfer: bool { default := false; }
spentBy: Policy { rewrite insert, update using (__subject__.result.transaction.policy) }

access policy members_can_select_insert
allow select, insert
using (is_member(.account));
}

abstract type Transferlike extending Event, TransferDetails {
spentBy: Policy { rewrite insert, update using (__subject__.systx.proposal.policy) }

index on ((.spentBy, .tokenAddress));
index on ((.tokenAddress, .confirmed, .spentBy));
}

type Transfer extending Transferlike {
constraint exclusive on ((.account, .block, .logIndex)); # Must be declared directly on type
constraint exclusive on ((.account, .systxHash, .logIndex)); # Must be declared directly on type

index on ((.account, .internal, .incoming));
}
Expand All @@ -57,6 +58,6 @@ module default {
);
required property delta := .amount - (.previous.amount ?? 0);

constraint exclusive on ((.account, .block, .logIndex)); # Must be declared directly on type
constraint exclusive on ((.account, .systxHash, .result, .logIndex)); # Must be declared directly on type
}
}
89 changes: 46 additions & 43 deletions api/dbschema/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,27 @@ export namespace $default {
"approver": Approver;
}
export type CloudProvider = "Apple" | "Google";
export interface Result extends std.$Object {
"transaction": Transaction;
"timestamp": Date;
"events": Event[];
"transfers": Transfer[];
"systx"?: SystemTx | null;
}
export interface Confirmed extends Result {
"block": bigint;
"ethFeePerGas": string;
"gasUsed": bigint;
"networkEthFee": string;
}
export interface Failure extends Result {
"reason"?: string | null;
}
export interface ConfirmedFailure extends Confirmed, Failure {}
export interface Success extends Result {
"response"?: string | null;
}
export interface ConfirmedSuccess extends Confirmed, Success {}
export interface UserLabelled extends Labelled {}
export interface Contact extends UserLabelled {
"user"?: User | null;
Expand All @@ -146,28 +167,12 @@ export namespace $default {
export interface Event extends std.$Object {
"account": Account;
"block": bigint;
"internal": boolean;
"logIndex": number;
"systxHash": string;
"timestamp": Date;
"systx"?: SystemTx | null;
}
export interface Result extends std.$Object {
"systxHash"?: string | null;
"timestamp": Date;
"systx"?: SystemTx | null;
"events": Event[];
"transaction": Transaction;
"transferApprovals": TransferApproval[];
"transfers": Transfer[];
}
export interface ReceiptResult extends Result {
"block": bigint;
"ethFeePerGas": string;
"gasUsed": bigint;
"networkEthFee": string;
}
export interface Failed extends ReceiptResult {
"reason"?: string | null;
"result"?: Result | null;
"confirmed": boolean;
"internal": boolean;
}
export interface Function extends std.$Object {
"selector": string;
Expand Down Expand Up @@ -202,6 +207,7 @@ export namespace $default {
"to": string;
"value"?: bigint | null;
}
export interface OptimisticSuccess extends Success {}
export interface PaymasterFees extends std.$Object {
"activation": string;
"total": string;
Expand All @@ -216,19 +222,19 @@ export namespace $default {
"proposal"?: Transaction | null;
"initState": boolean;
"isActive": boolean;
"isDraft": boolean;
"latest"?: PolicyState | null;
"isLatest": boolean;
"isDraft": boolean;
}
export interface Policy extends PolicyState {
"approvers": Approver[];
"hash": string;
"actions": Action[];
"transfers": TransfersConfig;
"allowMessages": boolean;
"delay": number;
"name": string;
"threshold": number;
"hash": string;
}
export interface Rejection extends ProposalResponse {}
export interface RemovedPolicy extends PolicyState {}
Expand All @@ -240,21 +246,17 @@ export namespace $default {
"responses": string[];
"success": boolean;
"timestamp": Date;
"transfers": TransferDetails[];
}
export interface Successful extends ReceiptResult {
"responses": string[];
"transfers": Transfer[];
}
export interface SystemTx extends std.$Object {
"proposal": Transaction;
"maxEthFeePerGas": string;
"maxNetworkEthFee": string;
"maxEthFees": string;
"ethPerFeeToken": string;
"hash": string;
"timestamp": Date;
"usdPerFeeToken": string;
"events": Event[];
"maxEthFees": string;
"result"?: Result | null;
}
export interface Token extends UserLabelled {
Expand All @@ -272,7 +274,6 @@ export namespace $default {
export interface Transaction extends Proposal {
"maxAmount": string;
"gasLimit": bigint;
"result"?: Result | null;
"executable": boolean;
"unorderedOperations": Operation[];
"operations": Operation[];
Expand All @@ -281,14 +282,14 @@ export namespace $default {
"feeToken": Token;
"maxAmountFp": bigint;
"paymasterEthFees": PaymasterFees;
"result"?: Result | null;
"status": TransactionStatus;
"systx"?: SystemTx | null;
"results": Result[];
"systxs": SystemTx[];
}
export type TransactionStatus = "Pending" | "Scheduled" | "Executing" | "Successful" | "Failed" | "Cancelled";
export interface TransferDetails extends std.$Object {
"account": Account;
export interface Transferlike extends Event {
"tokenAddress": string;
"token"?: Token | null;
"amount": string;
Expand All @@ -297,8 +298,6 @@ export namespace $default {
"isFeeTransfer": boolean;
"outgoing": boolean;
"to": string;
}
export interface Transferlike extends Event, TransferDetails {
"spentBy"?: Policy | null;
}
export interface Transfer extends Transferlike {}
Expand Down Expand Up @@ -336,31 +335,33 @@ export type ApprovalIssue = $default.ApprovalIssue;
export type Approver = $default.Approver;
export type ApproverDetails = $default.ApproverDetails;
export type CloudProvider = $default.CloudProvider;
export type Result = $default.Result;
export type Confirmed = $default.Confirmed;
export type Failure = $default.Failure;
export type ConfirmedFailure = $default.ConfirmedFailure;
export type Success = $default.Success;
export type ConfirmedSuccess = $default.ConfirmedSuccess;
export type UserLabelled = $default.UserLabelled;
export type Contact = $default.Contact;
export type Contract = $default.Contract;
export type Event = $default.Event;
export type Result = $default.Result;
export type ReceiptResult = $default.ReceiptResult;
export type Failed = $default.Failed;
export type Function = $default.Function;
export type GlobalLabel = $default.GlobalLabel;
export type Proposal = $default.Proposal;
export type Message = $default.Message;
export type Operation = $default.Operation;
export type OptimisticSuccess = $default.OptimisticSuccess;
export type PaymasterFees = $default.PaymasterFees;
export type PolicyState = $default.PolicyState;
export type Policy = $default.Policy;
export type Rejection = $default.Rejection;
export type RemovedPolicy = $default.RemovedPolicy;
export type Scheduled = $default.Scheduled;
export type Simulation = $default.Simulation;
export type Successful = $default.Successful;
export type SystemTx = $default.SystemTx;
export type Token = $default.Token;
export type Transaction = $default.Transaction;
export type TransactionStatus = $default.TransactionStatus;
export type TransferDetails = $default.TransferDetails;
export type Transferlike = $default.Transferlike;
export type Transfer = $default.Transfer;
export type TransferApproval = $default.TransferApproval;
Expand Down Expand Up @@ -641,31 +642,33 @@ export interface types {
"Approver": $default.Approver;
"ApproverDetails": $default.ApproverDetails;
"CloudProvider": $default.CloudProvider;
"Result": $default.Result;
"Confirmed": $default.Confirmed;
"Failure": $default.Failure;
"ConfirmedFailure": $default.ConfirmedFailure;
"Success": $default.Success;
"ConfirmedSuccess": $default.ConfirmedSuccess;
"UserLabelled": $default.UserLabelled;
"Contact": $default.Contact;
"Contract": $default.Contract;
"Event": $default.Event;
"Result": $default.Result;
"ReceiptResult": $default.ReceiptResult;
"Failed": $default.Failed;
"Function": $default.Function;
"GlobalLabel": $default.GlobalLabel;
"Proposal": $default.Proposal;
"Message": $default.Message;
"Operation": $default.Operation;
"OptimisticSuccess": $default.OptimisticSuccess;
"PaymasterFees": $default.PaymasterFees;
"PolicyState": $default.PolicyState;
"Policy": $default.Policy;
"Rejection": $default.Rejection;
"RemovedPolicy": $default.RemovedPolicy;
"Scheduled": $default.Scheduled;
"Simulation": $default.Simulation;
"Successful": $default.Successful;
"SystemTx": $default.SystemTx;
"Token": $default.Token;
"Transaction": $default.Transaction;
"TransactionStatus": $default.TransactionStatus;
"TransferDetails": $default.TransferDetails;
"Transferlike": $default.Transferlike;
"Transfer": $default.Transfer;
"TransferApproval": $default.TransferApproval;
Expand Down
Loading

0 comments on commit f18cb99

Please sign in to comment.