From 9cb2d37757e3e2492e87026564308b200964dc84 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 19 Nov 2024 21:43:20 +0100 Subject: [PATCH] fix(rwa): fix the pact functions after last contract update (#2670) --- .changeset/wicked-rocks-cross.md | 2 ++ .../components/AddAgentForm/AddAgentForm.tsx | 2 ++ packages/apps/rwa-demo/src/constants.ts | 4 ++-- packages/apps/rwa-demo/src/hooks/getAgents.ts | 4 ++-- .../apps/rwa-demo/src/services/addAgent.ts | 4 ++-- .../rwa-demo/src/services/deleteIdentity.ts | 2 +- .../rwa-demo/src/services/distributeTokens.ts | 2 +- .../apps/rwa-demo/src/services/isAgent.ts | 2 +- .../rwa-demo/src/services/registerIdentity.ts | 19 +++++++++++++++---- .../apps/rwa-demo/src/services/removeAgent.ts | 4 ++-- 10 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 .changeset/wicked-rocks-cross.md diff --git a/.changeset/wicked-rocks-cross.md b/.changeset/wicked-rocks-cross.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/wicked-rocks-cross.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/apps/rwa-demo/src/components/AddAgentForm/AddAgentForm.tsx b/packages/apps/rwa-demo/src/components/AddAgentForm/AddAgentForm.tsx index 8efc0fb954..a6b208d122 100644 --- a/packages/apps/rwa-demo/src/components/AddAgentForm/AddAgentForm.tsx +++ b/packages/apps/rwa-demo/src/components/AddAgentForm/AddAgentForm.tsx @@ -41,12 +41,14 @@ export const AddAgentForm: FC = ({ onClose }) => { try { const tx = await addAgent(data, account!); + console.log(tx); const signedTransaction = await sign(tx); if (!signedTransaction) return; const client = getClient(); const res = await client.submit(signedTransaction); + console.log({ res }); addTransaction({ ...res, type: 'ADDAGENT', diff --git a/packages/apps/rwa-demo/src/constants.ts b/packages/apps/rwa-demo/src/constants.ts index b9828b58e6..80fc7efff3 100644 --- a/packages/apps/rwa-demo/src/constants.ts +++ b/packages/apps/rwa-demo/src/constants.ts @@ -2,6 +2,6 @@ export const ACCOUNT_COOKIE_NAME = 'spirekey'; // todo: this is temporary for devnet export const ADMIN = { - account: 'k:dd127c8553f430849069ba54e4edc3bf5e8ed0cfa62b33b37da6ee638cb79e55', - publicKey: 'dd127c8553f430849069ba54e4edc3bf5e8ed0cfa62b33b37da6ee638cb79e55', + account: 'k:a56eb32f7860bfc4e19ec4d4ac0b2dd6c9a96f3c72d607847416253422a2b1b7', + publicKey: 'a56eb32f7860bfc4e19ec4d4ac0b2dd6c9a96f3c72d607847416253422a2b1b7', }; diff --git a/packages/apps/rwa-demo/src/hooks/getAgents.ts b/packages/apps/rwa-demo/src/hooks/getAgents.ts index f25341a222..857e631bf8 100644 --- a/packages/apps/rwa-demo/src/hooks/getAgents.ts +++ b/packages/apps/rwa-demo/src/hooks/getAgents.ts @@ -27,13 +27,13 @@ export const useGetAgents = () => { error, } = useEventsQuery({ variables: { - qualifiedName: 'RWA.agent-role.AGENT-ADDED', + qualifiedName: 'RWA.mvp-token.AGENT-ADDED', }, }); const { data: removedData, loading: removedLoading } = useEventsQuery({ variables: { - qualifiedName: 'RWA.agent-role.AGENT-REMOVED', + qualifiedName: 'RWA.mvp-token.AGENT-REMOVED', }, }); diff --git a/packages/apps/rwa-demo/src/services/addAgent.ts b/packages/apps/rwa-demo/src/services/addAgent.ts index ea9db542a8..89beb061be 100644 --- a/packages/apps/rwa-demo/src/services/addAgent.ts +++ b/packages/apps/rwa-demo/src/services/addAgent.ts @@ -16,14 +16,14 @@ export const addAgent = async ( ) => { return Pact.builder .execution( - `(RWA.agent-role.add-agent (read-string 'agent) (read-keyset 'agent_guard))`, + `(RWA.mvp-token.add-agent (read-string 'agent) (read-keyset 'agent_guard))`, ) .setMeta({ senderAccount: account.address, chainId: getNetwork().chainId, }) .addSigner(account.keyset.guard.keys[0], (withCap) => [ - withCap(`RWA.agent-role.ONLY-OWNER`), + withCap(`RWA.mvp-token.ONLY-OWNER`, ''), withCap(`coin.GAS`), ]) .addData('agent', data.agent) diff --git a/packages/apps/rwa-demo/src/services/deleteIdentity.ts b/packages/apps/rwa-demo/src/services/deleteIdentity.ts index 19b77c4921..c6523604dc 100644 --- a/packages/apps/rwa-demo/src/services/deleteIdentity.ts +++ b/packages/apps/rwa-demo/src/services/deleteIdentity.ts @@ -19,7 +19,7 @@ export const deleteIdentity = async ( chainId: getNetwork().chainId, }) .addSigner(account.keyset.guard.keys[0], (withCap) => [ - withCap(`RWA.agent-role.ONLY-AGENT`, account.address), + withCap(`RWA.mvp-token.ONLY-AGENT`, account.address), withCap(`coin.GAS`), ]) .addData('investor', data.investor) diff --git a/packages/apps/rwa-demo/src/services/distributeTokens.ts b/packages/apps/rwa-demo/src/services/distributeTokens.ts index 06c94a7909..8a5ff0ba7d 100644 --- a/packages/apps/rwa-demo/src/services/distributeTokens.ts +++ b/packages/apps/rwa-demo/src/services/distributeTokens.ts @@ -33,7 +33,7 @@ export const distributeTokens = async ( chainId: getNetwork().chainId, }) .addSigner(account.keyset.guard.keys[0], (withCap) => [ - withCap(`RWA.agent-role.ONLY-AGENT`, account.address), + withCap(`RWA.mvp-token.ONLY-AGENT`, account.address), withCap( `RWA.mvp-token.TRANSFER`, 'c:soLScugf2M-6r5L-leMUCGvgddyB1qaKh9s7ka4upGU', diff --git a/packages/apps/rwa-demo/src/services/isAgent.ts b/packages/apps/rwa-demo/src/services/isAgent.ts index dff4f4d8dd..e3f135776d 100644 --- a/packages/apps/rwa-demo/src/services/isAgent.ts +++ b/packages/apps/rwa-demo/src/services/isAgent.ts @@ -9,7 +9,7 @@ export const isAgent = async (data: IIsAgentProps) => { const client = getClient(); const transaction = Pact.builder - .execution(`(RWA.agent-role.is-agent (read-string 'agent))`) + .execution(`(RWA.mvp-token.is-agent (read-string 'agent))`) .setMeta({ senderAccount: data.agent, chainId: getNetwork().chainId, diff --git a/packages/apps/rwa-demo/src/services/registerIdentity.ts b/packages/apps/rwa-demo/src/services/registerIdentity.ts index 1eaa913e8c..8a0c214d6b 100644 --- a/packages/apps/rwa-demo/src/services/registerIdentity.ts +++ b/packages/apps/rwa-demo/src/services/registerIdentity.ts @@ -7,21 +7,32 @@ export interface IRegisterIdentityProps { agent: IWalletAccount; } +const createPubKeyFromAccount = (account: string): string => { + return account.replace('k:', '').replace('r:', ''); +}; + export const registerIdentity = async (data: IRegisterIdentityProps) => { return Pact.builder .execution( - `(RWA.identity-registry.register-identity (read-string 'investor) "" 1 (read-string 'agent))`, + `(RWA.mvp-token.register-identity (read-string 'investor) (read-string 'agent) 1) + (RWA.mvp-token.create-account (read-string 'investor) (read-keyset 'investor-keyset)) + `, ) + .addData('investor-keyset', { + keys: [createPubKeyFromAccount(data.investor)], + pred: 'keys-all', + }) + .addData('investor', data.investor) + .addData('agent', data.agent.address) .setMeta({ senderAccount: data.agent.address, chainId: getNetwork().chainId, }) .addSigner(data.agent.keyset.guard.keys[0], (withCap) => [ - withCap(`RWA.agent-role.ONLY-AGENT`, data.agent.address), + withCap(`RWA.mvp-token.ONLY-AGENT`, data.agent.address), withCap(`coin.GAS`), ]) - .addData('investor', data.investor) - .addData('agent', data.agent.address) + .setNetworkId(getNetwork().networkId) .createTransaction(); }; diff --git a/packages/apps/rwa-demo/src/services/removeAgent.ts b/packages/apps/rwa-demo/src/services/removeAgent.ts index aa48dd0e3f..78943c58b2 100644 --- a/packages/apps/rwa-demo/src/services/removeAgent.ts +++ b/packages/apps/rwa-demo/src/services/removeAgent.ts @@ -12,13 +12,13 @@ export const removeAgent = async ( account: IWalletAccount, ) => { return Pact.builder - .execution(`(RWA.agent-role.remove-agent (read-string 'agent))`) + .execution(`(RWA.mvp-token.remove-agent (read-string 'agent))`) .setMeta({ senderAccount: ADMIN.account, chainId: getNetwork().chainId, }) .addSigner(ADMIN.publicKey, (withCap) => [ - withCap(`RWA.agent-role.ONLY-OWNER`), + withCap(`RWA.mvp-token.ONLY-OWNER`), withCap(`coin.GAS`), ]) .addData('agent', data.agent)