Skip to content

Commit

Permalink
fix(rwa): fix the pact functions after last contract update (#2670)
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans authored Nov 19, 2024
1 parent d89008c commit 9cb2d37
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .changeset/wicked-rocks-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ export const AddAgentForm: FC<IProps> = ({ 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',
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/rwa-demo/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
4 changes: 2 additions & 2 deletions packages/apps/rwa-demo/src/hooks/getAgents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});

Expand Down
4 changes: 2 additions & 2 deletions packages/apps/rwa-demo/src/services/addAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/rwa-demo/src/services/deleteIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/rwa-demo/src/services/distributeTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/rwa-demo/src/services/isAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 15 additions & 4 deletions packages/apps/rwa-demo/src/services/registerIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
4 changes: 2 additions & 2 deletions packages/apps/rwa-demo/src/services/removeAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9cb2d37

Please sign in to comment.