Skip to content

Commit

Permalink
feat: pass real chainId and treasuryName
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekhmet committed Jul 26, 2024
1 parent 8b6f741 commit 588dc06
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 102 deletions.
52 changes: 27 additions & 25 deletions apps/ui/src/composables/useActions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getInstance } from '@snapshot-labs/lock/plugins/vue3';
import { registerTransaction } from '@/helpers/mana';
import { getNetwork, getReadWriteNetwork, metadataNetwork } from '@/networks';
import { Connector, StrategyConfig } from '@/networks/types';
import { Connector, ExecutionInfo, StrategyConfig } from '@/networks/types';
import {
Choice,
NetworkID,
Expand Down Expand Up @@ -262,9 +262,7 @@ export function useActions() {
discussion: string,
type: VoteType,
choices: string[],
executionStrategy: string | null,
executionDestinationAddress: string | null,
execution: Transaction[]
executionInfo: ExecutionInfo | null
) {
if (!web3.value.account) {
forceLogin();
Expand All @@ -273,18 +271,13 @@ export function useActions() {

const network = getNetwork(space.network);

const transactions = execution.map((tx: Transaction) => ({
...tx,
operation: 0
}));

const pinned = await network.helpers.pin({
title,
body,
discussion,
type,
choices: choices.filter(c => !!c),
execution: transactions
execution: executionInfo?.transactions ?? []
});
if (!pinned || !pinned.cid) return false;
console.log('IPFS', pinned);
Expand All @@ -297,9 +290,17 @@ export function useActions() {
web3.value.account,
space,
pinned.cid,
executionStrategy,
executionDestinationAddress,
transactions
executionInfo === null
? executionInfo
: {
...executionInfo,
transactions: executionInfo.transactions.map(
(tx: Transaction) => ({
...tx,
operation: 0
})
)
}
)
);

Expand All @@ -319,9 +320,7 @@ export function useActions() {
discussion: string,
type: VoteType,
choices: string[],
executionStrategy: string | null,
executionDestinationAddress: string | null,
execution: Transaction[]
executionInfo: ExecutionInfo | null
) {
if (!web3.value.account) {
forceLogin();
Expand All @@ -330,18 +329,13 @@ export function useActions() {

const network = getNetwork(space.network);

const transactions = execution.map((tx: Transaction) => ({
...tx,
operation: 0
}));

const pinned = await network.helpers.pin({
title,
body,
discussion,
type,
choices: choices.filter(c => !!c),
execution: transactions
execution: executionInfo?.transactions ?? []
});
if (!pinned || !pinned.cid) return false;
console.log('IPFS', pinned);
Expand All @@ -355,9 +349,17 @@ export function useActions() {
space,
proposalId,
pinned.cid,
executionStrategy,
executionDestinationAddress,
transactions
executionInfo === null
? executionInfo
: {
...executionInfo,
transactions: executionInfo.transactions.map(
(tx: Transaction) => ({
...tx,
operation: 0
})
)
}
)
);

Expand Down
3 changes: 2 additions & 1 deletion apps/ui/src/networks/common/graphqlApi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ function formatSpace(space: ApiSpace, networkId: NetworkID): Space {
return {
name,
network,
address
address,
chainId: CHAIN_IDS[network]
};
}),
delegations: space.metadata.delegations.map(delegation => {
Expand Down
32 changes: 14 additions & 18 deletions apps/ui/src/networks/evm/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from '@/networks/common/helpers';
import {
Connector,
ExecutionInfo,
NetworkActions,
NetworkHelpers,
SnapshotInfo,
Expand All @@ -39,8 +40,7 @@ import {
Proposal,
Space,
SpaceMetadata,
StrategyParsedMetadata,
Transaction
StrategyParsedMetadata
} from '@/types';

const CONFIGS: Record<number, EvmNetworkConfig> = {
Expand Down Expand Up @@ -201,9 +201,7 @@ export function createActions(
account: string,
space: Space,
cid: string,
executionStrategy: string | null,
executionDestinationAddress: string | null,
transactions: Transaction[]
executionInfo: ExecutionInfo | null
) => {
await verifyNetwork(web3, chainId);

Expand All @@ -220,14 +218,14 @@ export function createActions(
});

let selectedExecutionStrategy;
if (executionStrategy) {
if (executionInfo) {
selectedExecutionStrategy = {
addr: executionStrategy,
addr: executionInfo.strategyAddress,
params: getExecutionData(
space,
executionStrategy,
executionDestinationAddress,
convertToMetaTransactions(transactions)
executionInfo.strategyAddress,
executionInfo.destinationAddress,
convertToMetaTransactions(executionInfo.transactions)
).executionParams[0]
};
} else {
Expand Down Expand Up @@ -286,9 +284,7 @@ export function createActions(
space: Space,
proposalId: number | string,
cid: string,
executionStrategy: string | null,
executionDestinationAddress: string | null,
transactions: Transaction[]
executionInfo: ExecutionInfo | null
) {
await verifyNetwork(web3, chainId);

Expand All @@ -304,14 +300,14 @@ export function createActions(
});

let selectedExecutionStrategy;
if (executionStrategy) {
if (executionInfo) {
selectedExecutionStrategy = {
addr: executionStrategy,
addr: executionInfo.strategyAddress,
params: getExecutionData(
space,
executionStrategy,
executionDestinationAddress,
convertToMetaTransactions(transactions)
executionInfo.strategyAddress,
executionInfo.destinationAddress,
convertToMetaTransactions(executionInfo.transactions)
).executionParams[0]
};
} else {
Expand Down
34 changes: 14 additions & 20 deletions apps/ui/src/networks/offchain/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
Space,
Statement,
StrategyParsedMetadata,
Transaction,
User,
UserProfile,
VoteType
Expand All @@ -32,6 +31,7 @@ import { EDITOR_APP_NAME, EDITOR_SNAPSHOT_OFFSET } from './constants';
import { getSdkChoice } from './helpers';
import {
Connector,
ExecutionInfo,
NetworkConstants,
NetworkHelpers,
ReadOnlyNetworkActions,
Expand All @@ -55,26 +55,24 @@ export function createActions(
networkConfig
});

async function getPlugins(
executionStrategy: string | null,
transactions: Transaction[]
) {
async function getPlugins(executionInfo: ExecutionInfo | null) {
const plugins = {} as { oSnap?: OSnapPlugin };
if (executionStrategy && transactions.length) {
const network = '11155111';
const treasuryAddress = executionStrategy;
if (executionInfo && executionInfo.transactions.length) {
const treasuryAddress = executionInfo.strategyAddress;
const moduleAddress = await getModuleAddressForTreasury(
network,
executionInfo.chainId.toString(),
treasuryAddress
);

plugins.oSnap = {
safes: [
{
safeName: 'Sekhmet treasury',
safeName: executionInfo.treasuryName,
safeAddress: treasuryAddress,
network,
transactions: transactions.map(tx => parseInternalTransaction(tx)),
network: executionInfo.chainId.toString(),
transactions: executionInfo.transactions.map(tx =>
parseInternalTransaction(tx)
),
moduleAddress
}
]
Expand All @@ -91,9 +89,7 @@ export function createActions(
account: string,
space: Space,
cid: string,
executionStrategy: string | null,
executionDestinationAddress: string | null,
transactions: Transaction[]
executionInfo: ExecutionInfo | null
) {
let payload: {
title: string;
Expand All @@ -114,7 +110,7 @@ export function createActions(
const startTime = currentTime + space.voting_delay;
const provider = getProvider(space.snapshot_chain_id as number);

const plugins = await getPlugins(executionStrategy, transactions);
const plugins = await getPlugins(executionInfo);

const data = {
space: space.id,
Expand All @@ -140,9 +136,7 @@ export function createActions(
space: Space,
proposalId: number | string,
cid: string,
executionStrategy: string | null,
executionDestinationAddress: string | null,
transactions: Transaction[]
executionInfo: ExecutionInfo | null
) {
let payload: {
title: string;
Expand All @@ -159,7 +153,7 @@ export function createActions(
throw new Error('Failed to fetch proposal metadata');
}

const plugins = await getPlugins(executionStrategy, transactions);
const plugins = await getPlugins(executionInfo);

const data = {
proposal: proposalId as string,
Expand Down
11 changes: 7 additions & 4 deletions apps/ui/src/networks/offchain/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@ function getProposalState(proposal: ApiProposal): ProposalState {
}

function formatSpace(space: ApiSpace, networkId: NetworkID): Space {
const treasuries = space.treasuries
const treasuries: SpaceMetadataTreasury[] = space.treasuries
.map(treasury => {
const chainId = parseInt(treasury.network, 10);

return {
name: treasury.name,
network: TREASURY_NETWORKS.get(parseInt(treasury.network, 10)),
address: treasury.address
network: TREASURY_NETWORKS.get(chainId) ?? null,
address: treasury.address,
chainId
};
})
.filter(treasury => !!treasury.network) as SpaceMetadataTreasury[];
.filter(treasury => !!treasury.network);

let validationName = space.validation.name;
const validationParams = space.validation.params || {};
Expand Down
32 changes: 14 additions & 18 deletions apps/ui/src/networks/starknet/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '@/networks/common/helpers';
import {
Connector,
ExecutionInfo,
NetworkActions,
NetworkHelpers,
SnapshotInfo,
Expand All @@ -35,8 +36,7 @@ import {
Proposal,
Space,
SpaceMetadata,
StrategyParsedMetadata,
Transaction
StrategyParsedMetadata
} from '@/types';

const CONFIGS: Partial<Record<NetworkID, NetworkConfig>> = {
Expand Down Expand Up @@ -196,9 +196,7 @@ export function createActions(
account: string,
space: Space,
cid: string,
executionStrategy: string | null,
executionDestinationAddress: string | null,
transactions: Transaction[]
executionInfo: ExecutionInfo | null
) => {
const isContract = await getIsContract(connectorType, account);

Expand All @@ -217,14 +215,14 @@ export function createActions(
}

let selectedExecutionStrategy;
if (executionStrategy) {
if (executionInfo) {
selectedExecutionStrategy = {
addr: executionStrategy,
addr: executionInfo.strategyAddress,
params: getExecutionData(
space,
executionStrategy,
executionDestinationAddress,
convertToMetaTransactions(transactions)
executionInfo.strategyAddress,
executionInfo.destinationAddress,
convertToMetaTransactions(executionInfo.transactions)
).executionParams
};
} else {
Expand Down Expand Up @@ -284,9 +282,7 @@ export function createActions(
space: Space,
proposalId: number | string,
cid: string,
executionStrategy: string | null,
executionDestinationAddress: string | null,
transactions: Transaction[]
executionInfo: ExecutionInfo | null
) {
const isContract = await getIsContract(connectorType, account);

Expand All @@ -304,14 +300,14 @@ export function createActions(
}

let selectedExecutionStrategy;
if (executionStrategy) {
if (executionInfo) {
selectedExecutionStrategy = {
addr: executionStrategy,
addr: executionInfo.strategyAddress,
params: getExecutionData(
space,
executionStrategy,
executionDestinationAddress,
convertToMetaTransactions(transactions)
executionInfo.strategyAddress,
executionInfo.destinationAddress,
convertToMetaTransactions(executionInfo.transactions)
).executionParams
};
} else {
Expand Down
Loading

0 comments on commit 588dc06

Please sign in to comment.