Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

Z 113 proposal dapp metadaa #204

Merged
merged 16 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
9 changes: 7 additions & 2 deletions api/dbschema/default.esdl
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ module default {
}

abstract type Proposal {
required hash: Bytes32 { constraint exclusive; }
required hash: Bytes32;
required account: Account;
policy: Policy;
label: Label;
iconUri: str;
iconUri: Url;
required validFrom: datetime;
required createdAt: datetime {
readonly := true;
Expand All @@ -50,6 +50,7 @@ module default {
readonly := true;
default := (<Approver>(global current_approver).id);
}
dapp: tuple<name: str, url: Url, icons: array<Url>>;
multi link approvals := .<proposal[is Approval];
multi link rejections := .<proposal[is Rejection];
multi link potentialApprovers := (
Expand All @@ -64,6 +65,8 @@ module default {
);
property riskLabel := assert_single((select .<proposal[is ProposalRiskLabel] filter .user = global current_user)).risk;

constraint exclusive on ((.hash, .account));

access policy members_only
allow all
using (.account in global current_accounts);
Expand Down Expand Up @@ -150,6 +153,8 @@ module default {
))
);
required property nonce := <bigint>math::floor(datetime_get(.validFrom, 'epochseconds'));

constraint exclusive on (.hash);
}

scalar type TransactionProposalStatus extending enum<'Pending', 'Executing', 'Successful', 'Failed'>;
Expand Down
5 changes: 4 additions & 1 deletion api/dbschema/edgeql-js/__spec__.ts

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions api/dbschema/edgeql-js/castMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type scalarAssignableBy<T extends $.ScalarType> =
T extends _std.$int32 ? _std.$int32 :
T extends _default.$current_accounts_set ? _default.$current_accounts_set :
T extends _std.$uuid ? _std.$uuid :
T extends _default.$Url ? _default.$Url :
T extends _default.$UAddress ? _default.$UAddress :
T extends _default.$TransferDirection ? _default.$TransferDirection :
T extends _default.$TransactionProposalStatus ? _default.$TransactionProposalStatus :
Expand Down Expand Up @@ -125,6 +126,7 @@ export type scalarCastableFrom<T extends $.ScalarType> =
T extends _std.$int32 ? _std.$int32 :
T extends _default.$current_accounts_set ? _default.$current_accounts_set :
T extends _std.$uuid ? _std.$uuid :
T extends _default.$Url ? _default.$Url :
T extends _default.$UAddress ? _default.$UAddress :
T extends _default.$TransferDirection ? _default.$TransferDirection :
T extends _default.$TransactionProposalStatus ? _default.$TransactionProposalStatus :
Expand Down Expand Up @@ -413,6 +415,12 @@ type getSharedParentScalar<A, B> =
:
never
:
A extends _default.$Url ?
B extends _default.$Url ?
B
:
never
:
A extends _default.$UAddress ?
B extends _default.$UAddress ?
B
Expand Down Expand Up @@ -838,6 +846,12 @@ function getSharedParentScalar<A extends $.ScalarType, B extends $.ScalarType>(a
}
throw new Error(`Types are not castable: ${a.__name__}, ${b.__name__}`);
}
if (a.__name__ === "default::Url") {
if(b.__name__ === "default::Url") {
return b;
}
throw new Error(`Types are not castable: ${a.__name__}, ${b.__name__}`);
}
if (a.__name__ === "default::UAddress") {
if(b.__name__ === "default::UAddress") {
return b;
Expand Down
14 changes: 10 additions & 4 deletions api/dbschema/edgeql-js/modules/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ const TransferDirection: $TransferDirection = $.makeType<$TransferDirection>(_.s
export type $UAddress = $.ScalarType<"std::str", string>;
const UAddress: $.scalarTypeWithConstructor<_std.$str, never> = $.makeType<$.scalarTypeWithConstructor<_std.$str, never>>(_.spec, "6055ec33-9eb1-11ee-b040-6512afc4d633", _.syntax.literal);

export type $Url = $.ScalarType<"std::str", string>;
const Url: $.scalarTypeWithConstructor<_std.$str, never> = $.makeType<$.scalarTypeWithConstructor<_std.$str, never>>(_.spec, "d5027c44-c661-11ee-8085-211a59ea5371", _.syntax.literal);

export type $current_accounts_set = $.ScalarType<"std::uuid", string>;
const current_accounts_set: $.scalarTypeWithConstructor<_std.$uuid, never> = $.makeType<$.scalarTypeWithConstructor<_std.$uuid, never>>(_.spec, "6055c7ea-9eb1-11ee-81f8-83dd695319ad", _.syntax.literal);

Expand Down Expand Up @@ -314,8 +317,6 @@ export type $ProposalλShape = $.typeutil.flatten<_std.$Object_8ce8c71ee4fa5f738
"account": $.LinkDesc<$Account, $.Cardinality.One, {}, false, false, false, false>;
"proposedBy": $.LinkDesc<$Approver, $.Cardinality.One, {}, false, false, true, true>;
"createdAt": $.PropertyDesc<_std.$datetime, $.Cardinality.One, false, false, true, true>;
"hash": $.PropertyDesc<$Bytes32, $.Cardinality.One, true, false, false, false>;
"iconUri": $.PropertyDesc<_std.$str, $.Cardinality.AtMostOne, false, false, false, false>;
"label": $.PropertyDesc<$Label, $.Cardinality.AtMostOne, false, false, false, false>;
"validFrom": $.PropertyDesc<_std.$datetime, $.Cardinality.One, false, false, false, false>;
"approvals": $.LinkDesc<$Approval, $.Cardinality.Many, {}, false, true, false, false>;
Expand All @@ -324,6 +325,9 @@ export type $ProposalλShape = $.typeutil.flatten<_std.$Object_8ce8c71ee4fa5f738
"policy": $.LinkDesc<$Policy, $.Cardinality.AtMostOne, {}, false, false, false, false>;
"potentialApprovers": $.LinkDesc<$Approver, $.Cardinality.Many, {}, false, true, false, false>;
"potentialRejectors": $.LinkDesc<$Approver, $.Cardinality.Many, {}, false, true, false, false>;
"hash": $.PropertyDesc<$Bytes32, $.Cardinality.One, false, false, false, false>;
"dapp": $.PropertyDesc<$.NamedTupleType<{name: _std.$str, url: $Url, icons: $.ArrayType<$Url>}>, $.Cardinality.AtMostOne, false, false, false, false>;
"iconUri": $.PropertyDesc<$Url, $.Cardinality.AtMostOne, false, false, false, false>;
"<proposal[is ProposalResponse]": $.LinkDesc<$ProposalResponse, $.Cardinality.Many, {}, false, false, false, false>;
"<proposal[is Approval]": $.LinkDesc<$Approval, $.Cardinality.Many, {}, false, false, false, false>;
"<proposal[is Rejection]": $.LinkDesc<$Rejection, $.Cardinality.Many, {}, false, false, false, false>;
Expand All @@ -335,7 +339,7 @@ export type $ProposalλShape = $.typeutil.flatten<_std.$Object_8ce8c71ee4fa5f738
}>;
type $Proposal = $.ObjectType<"default::Proposal", $ProposalλShape, null, [
..._std.$Object_8ce8c71ee4fa5f73840c22d7eaa58588['__exclusives__'],
{hash: {__element__: $Bytes32, __cardinality__: $.Cardinality.One | $.Cardinality.AtMostOne },},
{hash: {__element__: $Bytes32, __cardinality__: $.Cardinality.One | $.Cardinality.AtMostOne },account: {__element__: $Account, __cardinality__: $.Cardinality.One | $.Cardinality.AtMostOne },},
]>;
const $Proposal = $.makeType<$Proposal>(_.spec, "611c412b-9eb1-11ee-a799-19af5ce2506a", _.syntax.literal);

Expand Down Expand Up @@ -841,7 +845,7 @@ const $default__globals: { current_accounts: _.syntax.$expr_Global<



export { AbiSource, Address, Amount, ApprovalIssue, Bytes, Bytes32, Bytes4, CloudProvider, Label, MAC, ProposalRisk, TransactionProposalStatus, TransferDirection, UAddress, current_accounts_set, uint16, uint224, uint256, uint32, uint64, $Account, Account, $Action, Action, $ActionFunction, ActionFunction, $ProposalResponse, ProposalResponse, $Approval, Approval, $Approver, Approver, $CloudShare, CloudShare, $Contact, Contact, $Contract, Contract, $Event, Event, $Function, Function, $Proposal, Proposal, $MessageProposal, MessageProposal, $Operation, Operation, $PaymasterFees, PaymasterFees, $Policy, Policy, $PolicyState, PolicyState, $ProposalRiskLabel, ProposalRiskLabel, $Receipt, Receipt, $Refund, Refund, $Rejection, Rejection, $Simulation, Simulation, $Token, Token, $Transaction, Transaction, $TransactionProposal, TransactionProposal, $TransferDetails, TransferDetails, $Transferlike, Transferlike, $Transfer, Transfer, $TransferApproval, TransferApproval, $TransferLimit, TransferLimit, $TransfersConfig, TransfersConfig, $User, User, $current_accounts, current_accounts, $current_approver, current_approver, $current_user, current_user };
export { AbiSource, Address, Amount, ApprovalIssue, Bytes, Bytes32, Bytes4, CloudProvider, Label, MAC, ProposalRisk, TransactionProposalStatus, TransferDirection, UAddress, Url, current_accounts_set, uint16, uint224, uint256, uint32, uint64, $Account, Account, $Action, Action, $ActionFunction, ActionFunction, $ProposalResponse, ProposalResponse, $Approval, Approval, $Approver, Approver, $CloudShare, CloudShare, $Contact, Contact, $Contract, Contract, $Event, Event, $Function, Function, $Proposal, Proposal, $MessageProposal, MessageProposal, $Operation, Operation, $PaymasterFees, PaymasterFees, $Policy, Policy, $PolicyState, PolicyState, $ProposalRiskLabel, ProposalRiskLabel, $Receipt, Receipt, $Refund, Refund, $Rejection, Rejection, $Simulation, Simulation, $Token, Token, $Transaction, Transaction, $TransactionProposal, TransactionProposal, $TransferDetails, TransferDetails, $Transferlike, Transferlike, $Transfer, Transfer, $TransferApproval, TransferApproval, $TransferLimit, TransferLimit, $TransfersConfig, TransfersConfig, $User, User, $current_accounts, current_accounts, $current_approver, current_approver, $current_user, current_user };

type __defaultExports = {
"AbiSource": typeof AbiSource;
Expand All @@ -858,6 +862,7 @@ type __defaultExports = {
"TransactionProposalStatus": typeof TransactionProposalStatus;
"TransferDirection": typeof TransferDirection;
"UAddress": typeof UAddress;
"Url": typeof Url;
"current_accounts_set": typeof current_accounts_set;
"uint16": typeof uint16;
"uint224": typeof uint224;
Expand Down Expand Up @@ -918,6 +923,7 @@ const __defaultExports: __defaultExports = {
"TransactionProposalStatus": TransactionProposalStatus,
"TransferDirection": TransferDirection,
"UAddress": UAddress,
"Url": Url,
"current_accounts_set": current_accounts_set,
"uint16": uint16,
"uint224": uint224,
Expand Down
5 changes: 3 additions & 2 deletions api/dbschema/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ export interface Proposal extends std.$Object {
"account": Account;
"proposedBy": Approver;
"createdAt": Date;
"hash": string;
"iconUri"?: string | null;
"label"?: string | null;
"validFrom": Date;
"approvals": Approval[];
Expand All @@ -158,6 +156,9 @@ export interface Proposal extends std.$Object {
"policy"?: Policy | null;
"potentialApprovers": Approver[];
"potentialRejectors": Approver[];
"hash": string;
"dapp"?: {name: string, url: string, icons: string[]} | null;
"iconUri"?: string | null;
}
export interface MessageProposal extends Proposal {
"message": string;
Expand Down
20 changes: 20 additions & 0 deletions api/dbschema/migrations/00004.edgeql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CREATE MIGRATION m1lzckoyyqqbnd3hkbo25xtfgspxje6p3ddt2tjygyio65uhu72ela
ONTO m1snled4gso2wkpig4ozz776xv3xrfsozyuwqznukjvip2nlvoycpq
{
CREATE SCALAR TYPE default::Url EXTENDING std::str {
CREATE CONSTRAINT std::regexp('^https?://');
};
ALTER TYPE default::Proposal {
CREATE CONSTRAINT std::exclusive ON ((.hash, .account));
CREATE PROPERTY dapp: tuple<name: std::str, url: default::Url, icons: array<default::Url>>;
ALTER PROPERTY hash {
DROP CONSTRAINT std::exclusive;
};
ALTER PROPERTY iconUri {
SET TYPE default::Url;
};
};
ALTER TYPE default::TransactionProposal {
CREATE CONSTRAINT std::exclusive ON (.hash);
};
};
4 changes: 4 additions & 0 deletions api/dbschema/scalars.esdl
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ module default {
scalar type Amount extending decimal {
constraint min_value(0.0n);
}

scalar type Url extending str {
constraint regexp(r'^https?://');
}
}
17 changes: 17 additions & 0 deletions api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ interface CustomNode {
id: ID!
}

type DappMetadata {
icons: [URL!]!
name: String!
url: URL!
}

input DappMetadataInput {
icons: [URL!]!
name: String!
url: URL!
}

"""
A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date-time format.
"""
Expand Down Expand Up @@ -300,6 +312,7 @@ type MessageProposal implements Node & Proposal {
account: Account!
approvals: [Approval!]!
createdAt: DateTime!
dapp: DappMetadata
hash: Bytes32!
iconUri: String
id: UUID!
Expand Down Expand Up @@ -429,6 +442,7 @@ interface Proposal implements Node {
account: Account!
approvals: [Approval!]!
createdAt: DateTime!
dapp: DappMetadata
hash: Bytes32!
iconUri: String
id: UUID!
Expand Down Expand Up @@ -476,6 +490,7 @@ input ProposalsInput {

input ProposeMessageInput {
account: UAddress!
dapp: DappMetadataInput
iconUri: String
label: String

Expand All @@ -490,6 +505,7 @@ input ProposeMessageInput {

input ProposeTransactionInput {
account: UAddress!
dapp: DappMetadataInput
feeToken: Address
gas: Uint256
iconUri: String
Expand Down Expand Up @@ -698,6 +714,7 @@ type TransactionProposal implements Node & Proposal {
account: Account!
approvals: [Approval!]!
createdAt: DateTime!
dapp: DappMetadata
estimatedFees: EstimatedTransactionFees!
feeToken: Token!
gasLimit: BigInt!
Expand Down
15 changes: 11 additions & 4 deletions api/src/features/activations/activations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,17 @@ export class ActivationsService {
if (!params) return null;

const network = this.networks.get(address);
return network.estimateContractGas({
account: asAddress(network.walletAddress),
...deployAccountProxyRequest(params),
});
try {
return await network.estimateContractGas({
account: asAddress(network.walletAddress),
...deployAccountProxyRequest(params),
});
} catch (e) {
const isDeployed = !!(await network.getBytecode({ address: asAddress(address) }))?.length;
if (isDeployed) return 0n;

throw e;
}
}

async params(address: UAddress) {
Expand Down
4 changes: 4 additions & 0 deletions api/src/features/message-proposals/message-proposals.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TypedDataDefinition } from 'viem';
import { UAddressField } from '~/apollo/scalars/UAddress.scalar';
import { BytesScalar } from '~/apollo/scalars/Bytes.scalar';
import { TypedDataField } from '~/apollo/scalars/TypedData.scalar';
import { DappMetadataInput } from '../proposals/proposals.input';

@InputType()
export class ProposeMessageInput {
Expand All @@ -22,6 +23,9 @@ export class ProposeMessageInput {
@Field(() => String, { nullable: true })
iconUri?: string;

@Field(() => DappMetadataInput, { nullable: true })
dapp?: DappMetadataInput;

@Field(() => Date, { nullable: true })
validFrom?: Date;

Expand Down
14 changes: 12 additions & 2 deletions api/src/features/message-proposals/message-proposals.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class MessageProposalsService {
return this.db.query(
e.select(e.MessageProposal, (p) => ({
...shape?.(p),
filter_single: isHex(id) ? { hash: id } : { id },
filter_single: { id },
})),
);
}
Expand All @@ -50,6 +50,7 @@ export class MessageProposalsService {
typedData,
label,
iconUri,
dapp,
validFrom = new Date(),
signature,
}: ProposeMessageInput) {
Expand All @@ -69,7 +70,11 @@ export class MessageProposalsService {

// upsert can't be used as exclusive hash constraint exists on parent type (Proposal)
const proposal =
(await this.db.query(e.select(e.MessageProposal, () => ({ filter_single: { hash } })))) ??
(await this.db.query(
e.select(e.MessageProposal, () => ({
filter_single: { hash, account: selectAccount(account) },
})),
)) ??
(await (async () => {
const p = await this.db.query(
e.insert(e.MessageProposal, {
Expand All @@ -79,6 +84,11 @@ export class MessageProposalsService {
typedData,
label,
iconUri,
dapp: dapp && {
name: dapp.name,
url: dapp.url.href,
icons: dapp.icons.map((i) => i.href),
},
validFrom,
}),
);
Expand Down
13 changes: 13 additions & 0 deletions api/src/features/proposals/proposals.input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Field, InputType, registerEnumType } from '@nestjs/graphql';
import { GraphQLURL } from 'graphql-scalars';
import { Address, Hex, PolicyKey, UAddress, UUID } from 'lib';
import { AddressField } from '~/apollo/scalars/Address.scalar';
import { Bytes32Field, BytesField } from '~/apollo/scalars/Bytes.scalar';
Expand Down Expand Up @@ -84,3 +85,15 @@ export class ProposalSubscriptionInput {
@Field(() => [ProposalEvent], { nullable: true, description: 'Defaults to all events' })
events?: ProposalEvent[];
}

@InputType()
export class DappMetadataInput {
@Field(() => String)
name: string;

@Field(() => GraphQLURL)
url: URL;

@Field(() => [GraphQLURL])
icons: URL[];
}
18 changes: 17 additions & 1 deletion api/src/features/proposals/proposals.model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import { Field, InterfaceType, registerEnumType } from '@nestjs/graphql';
import { Field, InterfaceType, ObjectType, registerEnumType } from '@nestjs/graphql';
import { Account } from '../accounts/accounts.model';
import { Policy } from '../policies/policies.model';
import { Bytes32Field } from '~/apollo/scalars/Bytes.scalar';
import { Approver } from '../approvers/approvers.model';
import { Node, NodeType } from '~/decorators/interface.decorator';
import { makeUnionTypeResolver } from '../database/database.util';
import { Risk } from './proposals.input';
import { GraphQLURL } from 'graphql-scalars';

@ObjectType()
export class DappMetadata {
@Field(() => String)
name: string;

@Field(() => GraphQLURL)
url: URL;

@Field(() => [GraphQLURL])
icons: URL[];
}

@InterfaceType({ implements: () => Node, resolveType: makeUnionTypeResolver() })
export class Proposal {
Expand Down Expand Up @@ -33,6 +46,9 @@ export class Proposal {
@Field(() => Approver)
proposedBy: Approver;

@Field(() => DappMetadata, { nullable: true })
dapp?: DappMetadata;

@Field(() => [Approval])
approvals: Approval[];

Expand Down
Loading
Loading