Skip to content

Commit 8a82838

Browse files
authored
chore(rwa): add changes to the contract (#2752)
1 parent ebc4e5c commit 8a82838

File tree

5 files changed

+74
-61
lines changed

5 files changed

+74
-61
lines changed

.changeset/early-jokes-fail.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/apps/rwa-demo/src/hooks/getAgentRoles.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const useGetAgentRoles = ({
4545

4646
const { data: subscriptionData } = useEventSubscriptionSubscription({
4747
variables: {
48-
qualifiedName: `${getAsset()}.ROLE_UPDATED`,
48+
qualifiedName: `${getAsset()}.AGENT-ROLES-UPDATED`,
4949
},
5050
});
5151

packages/apps/rwa-demo/src/hooks/getInvestors.ts

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ export const useGetInvestors = () => {
136136

137137
useEffect(() => {
138138
if (removedLoading || addedLoading) return;
139-
//const tx = getTransactions('IDENTITY-REGISTERED');
140139
// eslint-disable-next-line @typescript-eslint/no-floating-promises
141140
initInnerData();
142141
}, [

packages/apps/rwa-demo/src/services/pact/modelcontract.ts

+70-57
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
119119
TOKEN-INFO-MANAGER
120120
])
121121
122+
(defschema schema-set-compliance-parameters
123+
supply-limit:decimal
124+
max-investors:integer
125+
max-balance-per-investor:decimal
126+
)
127+
128+
(defcap SET-COMPLIANCE-PARAMETERS:bool (compliance:object{schema-set-compliance-parameters})
129+
@doc "Event emitted when a compliance parameters is updated."
130+
@event
131+
true
132+
)
133+
122134
;; compliance-compatible functions
123135
124136
(defun set-max-balance-per-investor (max-balance-per-investor:decimal)
@@ -151,7 +163,7 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
151163
(update compliance-parameters ""
152164
compliance-params
153165
)
154-
(emit-event (SET-COMPLIANCE-PARAMETERS (read-msg 'compliance-parameters )))
166+
(emit-event (SET-COMPLIANCE-PARAMETERS compliance-params))
155167
)
156168
)
157169
@@ -209,18 +221,6 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
209221
true
210222
)
211223
212-
(defschema schema-set-compliance-parameters
213-
supply-limit: decimal
214-
max-investors: integer
215-
max-balance-per-investor: decimal
216-
)
217-
218-
(defcap SET-COMPLIANCE-PARAMETERS:bool (compliance:object{schema-set-compliance-parameters})
219-
@doc "Event emitted when a compliance parameters is updated."
220-
@event
221-
true
222-
)
223-
224224
(defcap RECOVERY-SUCCESS:bool (lost-wallet:string new-wallet:string investor-kadenaID:string)
225225
@doc "Event emitted when a recovery process is successful."
226226
@event
@@ -257,27 +257,16 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
257257
true
258258
)
259259
260-
(defcap ROLE_UPDATED:bool (user-address:string roles:[string])
261-
@doc ""
260+
(defcap AGENT-ROLES-UPDATED:bool (user-address:string roles:[string])
261+
@doc "Event emitted when agent role is updated"
262262
@event
263263
true
264264
)
265265
266-
267-
268266
;; grant caps
269267
270268
(defcap INTERNAL:bool () true)
271269
(defcap MINT:bool () true)
272-
(defcap RECONCILE:bool (to:string amount:decimal)
273-
@doc "Event emitted when there are tokens minted to an investor"
274-
@event
275-
true
276-
)
277-
278-
279-
280-
281270
(defcap BURN:bool () true)
282271
(defcap FORCED-TRANSFER:bool () true )
283272
(defcap UPDATE-SUPPLY:bool () true )
@@ -343,7 +332,7 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
343332
true
344333
)
345334
346-
(defcap IDENTITY-REGISTERED:bool (investor-address:string identity:string)
335+
(defcap IDENTITY-REGISTERED:bool (investor-address:string investor-guard:guard identity:string)
347336
@doc "This event is emitted when an Identity is registered into the Identity Registry. \
348337
\ The event is emitted by the 'register-identity' function. \
349338
\ \`investor-address\` is the address of the investor's wallet. \
@@ -591,11 +580,12 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
591580
592581
(defun forced-transfer:bool (from:string to:string amount:decimal)
593582
@doc "Force transfer tokens from one address to another."
594-
(with-capability (FORCED-TRANSFER from to amount)
583+
(with-capability (FORCED-TRANSFER)
595584
(with-capability (TRANSFER from to amount)
596585
(only-agent TRANSFER-MANAGER)
597586
(transfer-internal from to amount)
598587
))
588+
true
599589
)
600590
601591
(defun mint :string (to:string amount:decimal)
@@ -645,11 +635,14 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
645635
(defun batch-forced-transfer:bool (from-list:[string] to-list:[string] amounts:[decimal])
646636
@doc "Perform batch forced transfer of tokens."
647637
(only-agent TRANSFER-MANAGER)
648-
(map (lambda (idx:integer)
649-
(with-capability (TRANSFER (at idx from-list) (at idx to-list) (at idx amounts))
650-
(transfer-internal (at idx from-list) (at idx to-list) (at idx amounts))
638+
(with-capability (FORCED-TRANSFER)
639+
(map (lambda (idx:integer)
640+
(with-capability (TRANSFER (at idx from-list) (at idx to-list) (at idx amounts))
641+
642+
(transfer-internal (at idx from-list) (at idx to-list) (at idx amounts))
643+
)
651644
)
652-
) (enumerate 0 (- (length from-list) 1)) ) true
645+
) (enumerate 0 (- (length from-list) 1)) ) true
653646
)
654647
655648
(defun batch-mint:bool (to-list:[string] amounts:[decimal])
@@ -667,21 +660,23 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
667660
(defun batch-burn:bool (user-addresses:[string] amounts:[decimal])
668661
@doc "Burn tokens from multiple addresses."
669662
(only-agent SUPPLY-MODIFIER)
670-
(map (lambda (idx:integer)
671-
(with-capability (TRANSFER (at idx user-addresses) (zero-address) (at idx amounts))
672-
(burn-internal (at idx user-addresses) (at idx amounts))
663+
(with-capability (BURN)
664+
(map (lambda (idx:integer)
665+
(with-capability (TRANSFER (at idx user-addresses) (zero-address) (at idx amounts))
666+
(burn-internal (at idx user-addresses) (at idx amounts))
667+
)
668+
) (enumerate 0 (- (length user-addresses) 1)) ) true
673669
)
674-
) (enumerate 0 (- (length user-addresses) 1)) ) true
675670
)
676671
677-
(defun batch-register-identity:bool (user-addresses:[string] identities:[string] countries:[integer])
672+
(defun batch-register-identity:bool (user-addresses:[string] user-guards:[guard] identities:[string] countries:[integer])
678673
@doc "Allows batch registration of identities. \
679674
\ Requires that none of the users has an identity contract already registered. \
680675
\ Only a wallet set as agent of the smart contract can call this function. \
681676
\ Emits \`IDENTITY-REGISTERED\` events for each user address in the batch."
682677
(only-agent WHITELIST-MANAGER)
683678
(map (lambda (idx:integer)
684-
(register-identity-internal (at idx user-addresses) (at idx identities) (at idx countries))
679+
(register-identity-internal (at idx user-addresses) (at idx user-guards) (at idx identities) (at idx countries))
685680
) (enumerate 0 (- (length user-addresses) 1)) ) true
686681
)
687682
@@ -736,7 +731,6 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
736731
(enforce-contains-identity to)
737732
(with-capability (TRANSFER (zero-address) to amount)
738733
(credit to amount)
739-
740734
(with-capability (UPDATE-SUPPLY)
741735
(update-supply amount)
742736
)
@@ -851,14 +845,25 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
851845
@managed amount TRANSFER-mgr
852846
853847
(if (try false (enforce-guard (at 'guard (read users sender))))
854-
true
848+
true ;; user signed for the transaction
849+
;;else
855850
(if (try false (require-capability (MINT)))
851+
;; mint is in action
856852
true
853+
;;else
857854
(if (try false (require-capability (BURN)))
855+
;;burn is in action
858856
true
857+
;; else
859858
(if (try false (require-capability (FORCED-TRANSFER)))
859+
;; forced-transfer is in action
860+
;; else fail
861+
true
862+
(enforce false "TRANSFER failed")
860863
)
861-
)))
864+
)
865+
)
866+
)
862867
863868
(enforce (!= sender "") "valid sender")
864869
(enforce (!= sender receiver) "same sender and receiver")
@@ -891,18 +896,18 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
891896
(with-default-read users account
892897
{"balance": -1.0}
893898
{ "balance" := balance}
894-
(if (= balance -1.0)
895-
(update users account
896-
{ "balance" : amount})
897-
(update users account
898-
{ "balance" : (+ balance amount)})
899-
)
900-
(if (= account (zero-address))
901-
"Credit to Zero Address"
902899
(if (= balance -1.0)
903-
[(add-investor-count)]
904-
"Credit successful"
900+
(update users account
901+
{ "balance" : amount})
902+
(update users account
903+
{ "balance" : (+ balance amount)})
905904
)
905+
(if (= account (zero-address))
906+
"Credit to Zero Address"
907+
(if (= balance -1.0)
908+
(add-investor-count)
909+
"Credit successful"
910+
)
906911
)
907912
)
908913
)
@@ -1118,15 +1123,14 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
11181123
@doc "Update agent roles"
11191124
(install-capability (ONLY-OWNER ""))
11201125
(install-capability (ONLY-AGENT AGENT-ADMIN))
1121-
11221126
(if (try false (only-owner ""))
11231127
true
11241128
(only-agent AGENT-ADMIN))
11251129
(verify-agent-roles roles)
11261130
(update agents agent
11271131
{ 'roles: roles }
11281132
)
1129-
(emit-event (ROLE_UPDATED agent roles))
1133+
(emit-event (AGENT-ROLES-UPDATED agent roles))
11301134
true
11311135
)
11321136
@@ -1147,23 +1151,31 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
11471151
(enumerate 0 (- (length roles) 1)))
11481152
))
11491153
1150-
(defun register-identity:bool (user-address:string identity:string country:integer)
1154+
(defun register-identity:bool (user-address:string user-guard:guard identity:string country:integer)
11511155
@doc "Register an identity contract corresponding to a user address. \
11521156
\ Requires that the user doesn't have an identity contract already registered. \
11531157
\ Only a wallet set as agent of the smart contract can call this function. \
11541158
\ Emits an \`IDENTITY-REGISTERED\` event."
11551159
(only-agent WHITELIST-MANAGER)
1156-
(register-identity-internal user-address identity country)
1160+
(register-identity-internal user-address user-guard identity country)
11571161
)
11581162
1159-
(defun register-identity-internal:bool (user-address:string identity:string country:integer)
1163+
(defun register-identity-internal:bool (user-address:string user-guard:guard identity:string country:integer)
11601164
@doc "Register an identity contract corresponding to a user address. \
11611165
\ Requires that the user doesn't have an identity contract already registered. \
11621166
\ Only a wallet set as agent of the smart contract can call this function. \
11631167
\ Emits an \`IDENTITY-REGISTERED\` event."
11641168
(is-principal user-address)
11651169
(write identities user-address { "kadenaID":identity, "country":country, "active":true })
1166-
(emit-event (IDENTITY-REGISTERED user-address identity))
1170+
(with-default-read users user-address
1171+
{ "balance": -2.0 }
1172+
{ "balance":=balance }
1173+
(if (= balance -2.0)
1174+
(create-account user-address user-guard)
1175+
""
1176+
)
1177+
)
1178+
(emit-event (IDENTITY-REGISTERED user-address user-guard identity))
11671179
)
11681180
11691181
@@ -1303,5 +1315,6 @@ export const getContract = ({ contractName, namespace }: IAddContractProps) => `
13031315
(RWA.token-mapper.add-token-ref TOKEN-ID ${namespace}.${contractName})
13041316
13051317
1318+
13061319
(${namespace}.${contractName}.init "${contractName}" "MVP" 0 "kadenaID" "0.0" [RWA.max-balance-compliance RWA.supply-limit-compliance] false (keyset-ref-guard "${namespace}.admin-keyset"))
13071320
`;

packages/apps/rwa-demo/src/services/registerIdentity.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ const createPubKeyFromAccount = (account: string): string => {
1818
export const registerIdentity = async (data: IRegisterIdentityProps) => {
1919
return Pact.builder
2020
.execution(
21-
`(${getAsset()}.register-identity (read-string 'investor) (read-string 'agent) 1)
22-
(${getAsset()}.create-account (read-string 'investor) (read-keyset 'investor-keyset))
21+
`(${getAsset()}.register-identity (read-string 'investor) (read-keyset 'investor-keyset) (read-string 'agent) 1)
2322
`,
2423
)
2524
.addData('investor-keyset', {

0 commit comments

Comments
 (0)