From 498727b61112bd142711d2a975d6d7fbba97ecfa Mon Sep 17 00:00:00 2001 From: olsemeno Date: Tue, 18 Jun 2024 09:37:38 +0200 Subject: [PATCH] Upgrade ImportICRC1Canister transaction as [sc-13093] --- packages/vaults/src/enum/enums.ts | 2 + packages/vaults/src/idl/idl.ts | 809 +++++++++--------- packages/vaults/src/idl/service_vault.ts | 640 +++++++------- packages/vaults/src/manager/vault_manager.ts | 24 - .../src/transaction/config/icrc1_add.ts | 79 ++ .../src/transaction/config/icrc1_remove.ts | 70 ++ .../vaults/src/transaction/config/index.ts | 2 + .../vaults/src/transaction/mapper_registry.ts | 9 + packages/vaults/src/vault_manager_i.ts | 17 - 9 files changed, 898 insertions(+), 754 deletions(-) create mode 100644 packages/vaults/src/transaction/config/icrc1_add.ts create mode 100644 packages/vaults/src/transaction/config/icrc1_remove.ts diff --git a/packages/vaults/src/enum/enums.ts b/packages/vaults/src/enum/enums.ts index 63e02682..7ec06166 100644 --- a/packages/vaults/src/enum/enums.ts +++ b/packages/vaults/src/enum/enums.ts @@ -20,6 +20,8 @@ export enum TransactionType { VersionUpgrade = "VersionUpgrade", Purge = "Purge", ControllerUpdate = "ControllerUpdate", + ICRC1AddCanisters = "ICRC1AddCanisters", + ICRC1RemoveCanisters = "ICRC1RemoveCanisters", } export enum Currency { diff --git a/packages/vaults/src/idl/idl.ts b/packages/vaults/src/idl/idl.ts index 12def885..9262917c 100644 --- a/packages/vaults/src/idl/idl.ts +++ b/packages/vaults/src/idl/idl.ts @@ -1,394 +1,415 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -export const idlFactory = ({ IDL }: any) => { - const TransactionState = IDL.Variant({ - Blocked: IDL.Null, - Failed: IDL.Null, - Approved: IDL.Null, - Rejected: IDL.Null, - Executed: IDL.Null, - Purged: IDL.Null, - Pending: IDL.Null, - }) - const TransactionApproveRequest = IDL.Record({ - transaction_id: IDL.Nat64, - state: TransactionState, - }) - const VaultError = IDL.Variant({ - ControllersUpdateError: IDL.Record({ message: IDL.Text }), - WalletNotExists: IDL.Null, - CouldNotDefinePolicy: IDL.Null, - ThresholdAlreadyExists: IDL.Null, - QuorumNotReachable: IDL.Null, - CanisterReject: IDL.Record({ message: IDL.Text }), - MemberNotExists: IDL.Null, - MemberAlreadyExists: IDL.Null, - ThresholdDefineError: IDL.Record({ message: IDL.Text }), - UIDAlreadyExists: IDL.Null, - PolicyNotExists: IDL.Null, - }) - const Approve = IDL.Record({ - status: TransactionState, - signer: IDL.Text, - created_date: IDL.Nat64, - }) - const BasicTransactionFields = IDL.Record({ - id: IDL.Nat64, - threshold: IDL.Opt(IDL.Nat8), - initiator: IDL.Text, - modified_date: IDL.Nat64, - memo: IDL.Opt(IDL.Text), - error: IDL.Opt(VaultError), - state: TransactionState, - approves: IDL.Vec(Approve), - is_vault_state: IDL.Bool, - created_date: IDL.Nat64, - batch_uid: IDL.Opt(IDL.Text), - }) - const ControllersUpdateTransaction = IDL.Record({ - principals: IDL.Vec(IDL.Principal), - common: BasicTransactionFields, - current_controllers: IDL.Vec(IDL.Principal), - }) - const Network = IDL.Variant({ - IC: IDL.Null, - BTC: IDL.Null, - ETH: IDL.Null, - }) - const WalletCreateTransaction = IDL.Record({ - uid: IDL.Text, - name: IDL.Text, - network: Network, - common: BasicTransactionFields, - }) - const Currency = IDL.Variant({ ICP: IDL.Null }) - const PolicyCreateTransaction = IDL.Record({ - uid: IDL.Text, - member_threshold: IDL.Nat8, - amount_threshold: IDL.Nat64, - wallets: IDL.Vec(IDL.Text), - currency: Currency, - common: BasicTransactionFields, - }) - const VaultRole = IDL.Variant({ Member: IDL.Null, Admin: IDL.Null }) - const MemberUpdateRoleTransaction = IDL.Record({ - role: VaultRole, - member_id: IDL.Text, - common: BasicTransactionFields, - }) - const TopUpTransaction = IDL.Record({ - block_index: IDL.Opt(IDL.Nat64), - currency: Currency, - wallet: IDL.Text, - common: BasicTransactionFields, - amount: IDL.Nat64, - policy: IDL.Opt(IDL.Text), - }) - const TopUpQuorumTransaction = IDL.Record({ - block_index: IDL.Opt(IDL.Nat64), - currency: Currency, - wallet: IDL.Text, - common: BasicTransactionFields, - amount: IDL.Nat64, - }) - const VaultNamingUpdateTransaction = IDL.Record({ - name: IDL.Opt(IDL.Text), - description: IDL.Opt(IDL.Text), - common: BasicTransactionFields, - }) - const TransferTransaction = IDL.Record({ - block_index: IDL.Opt(IDL.Nat64), - currency: Currency, - address: IDL.Text, - wallet: IDL.Text, - common: BasicTransactionFields, - amount: IDL.Nat64, - policy: IDL.Opt(IDL.Text), - }) - const PolicyRemoveTransaction = IDL.Record({ - uid: IDL.Text, - common: BasicTransactionFields, - }) - const SubAccount = IDL.Vec(IDL.Nat8) - const Account = IDL.Record({ - owner: IDL.Principal, - subaccount: IDL.Opt(SubAccount), - }) - const MemberExtendICRC1AccountTransaction = IDL.Record({ - account: Account, - batch_uid: IDL.Opt(IDL.Text), - common: BasicTransactionFields, - }) - const PolicyUpdateTransaction = IDL.Record({ - uid: IDL.Text, - member_threshold: IDL.Nat8, - amount_threshold: IDL.Nat64, - common: BasicTransactionFields, - }) - const TransferICRC1QuorumTransaction = IDL.Record({ - to_principal: IDL.Principal, - block_index: IDL.Opt(IDL.Nat), - to_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), - ledger_id: IDL.Principal, - wallet: IDL.Text, - common: BasicTransactionFields, - amount: IDL.Nat64, - }) - const MemberCreateTransaction = IDL.Record({ - name: IDL.Text, - role: VaultRole, - member_id: IDL.Text, - common: BasicTransactionFields, - }) - const MemberUpdateNameTransaction = IDL.Record({ - name: IDL.Text, - member_id: IDL.Text, - common: BasicTransactionFields, - }) - const VersionUpgradeTransaction = IDL.Record({ - version: IDL.Text, - initial_version: IDL.Text, - common: BasicTransactionFields, - }) - const PurgeTransaction = IDL.Record({ common: BasicTransactionFields }) - const TransferQuorumTransaction = IDL.Record({ - block_index: IDL.Opt(IDL.Nat64), - currency: Currency, - address: IDL.Text, - wallet: IDL.Text, - common: BasicTransactionFields, - amount: IDL.Nat64, - }) - const QuorumUpdateTransaction = IDL.Record({ - common: BasicTransactionFields, - quorum: IDL.Nat8, - }) - const MemberCreateTransactionV2 = IDL.Record({ - name: IDL.Text, - role: VaultRole, - account: Account, - common: BasicTransactionFields, - }) - const WalletUpdateNameTransaction = IDL.Record({ - uid: IDL.Text, - name: IDL.Text, - common: BasicTransactionFields, - }) - const MemberRemoveTransaction = IDL.Record({ - member_id: IDL.Text, - common: BasicTransactionFields, - }) - const TransactionCandid = IDL.Variant({ - ControllersUpdateTransactionV: ControllersUpdateTransaction, - WalletCreateTransactionV: WalletCreateTransaction, - PolicyCreateTransactionV: PolicyCreateTransaction, - MemberUpdateRoleTransactionV: MemberUpdateRoleTransaction, - TopUpTransactionV: TopUpTransaction, - TopUpQuorumTransactionV: TopUpQuorumTransaction, - VaultNamingUpdateTransactionV: VaultNamingUpdateTransaction, - TransferTransactionV: TransferTransaction, - PolicyRemoveTransactionV: PolicyRemoveTransaction, - MemberExtendICRC1AccountTransactionV: MemberExtendICRC1AccountTransaction, - PolicyUpdateTransactionV: PolicyUpdateTransaction, - TransferICRC1QuorumTransactionV: TransferICRC1QuorumTransaction, - MemberCreateTransactionV: MemberCreateTransaction, - MemberUpdateNameTransactionV: MemberUpdateNameTransaction, - UpgradeTransactionV: VersionUpgradeTransaction, - PurgeTransactionV: PurgeTransaction, - TransferQuorumTransactionV: TransferQuorumTransaction, - QuorumUpdateTransactionV: QuorumUpdateTransaction, - MemberCreateTransactionV2: MemberCreateTransactionV2, - WalletUpdateNameTransactionV: WalletUpdateNameTransaction, - MemberRemoveTransactionV: MemberRemoveTransaction, - }) - const Member = IDL.Record({ - modified_date: IDL.Nat64, - name: IDL.Text, - role: VaultRole, - account: IDL.Opt(Account), - member_id: IDL.Text, - created_date: IDL.Nat64, - }) - const ICRC1 = IDL.Record({ - ledger: IDL.Principal, - index: IDL.Opt(IDL.Principal), - }) - const Wallet = IDL.Record({ - uid: IDL.Text, - modified_date: IDL.Nat64, - name: IDL.Text, - network: Network, - created_date: IDL.Nat64, - }) - const Quorum = IDL.Record({ - modified_date: IDL.Nat64, - quorum: IDL.Nat8, - }) - const Policy = IDL.Record({ - uid: IDL.Text, - member_threshold: IDL.Nat8, - modified_date: IDL.Nat64, - amount_threshold: IDL.Nat64, - wallets: IDL.Vec(IDL.Text), - currency: Currency, - created_date: IDL.Nat64, - }) - const VaultState = IDL.Record({ - members: IDL.Vec(Member), - name: IDL.Opt(IDL.Text), - description: IDL.Opt(IDL.Text), - icrc1_canisters: IDL.Vec(ICRC1), - wallets: IDL.Vec(Wallet), - quorum: Quorum, - policies: IDL.Vec(Policy), - }) - const QuorumUpdateTransactionRequest = IDL.Record({ - quorum: IDL.Nat8, - batch_uid: IDL.Opt(IDL.Text), - }) - const VaultNamingUpdateTransactionRequest = IDL.Record({ - name: IDL.Opt(IDL.Text), - description: IDL.Opt(IDL.Text), - batch_uid: IDL.Opt(IDL.Text), - }) - const ControllersUpdateTransactionRequest = IDL.Record({ - principals: IDL.Vec(IDL.Principal), - }) - const MemberUpdateNameTransactionRequest = IDL.Record({ - name: IDL.Text, - member_id: IDL.Text, - batch_uid: IDL.Opt(IDL.Text), - }) - const TopUpTransactionRequest = IDL.Record({ - currency: Currency, - wallet: IDL.Text, - amount: IDL.Nat64, - }) - const TransferICRC1QuorumTransactionRequest = IDL.Record({ - to_principal: IDL.Principal, - to_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), - memo: IDL.Opt(IDL.Text), - ledger_id: IDL.Principal, - wallet: IDL.Text, - amount: IDL.Nat64, - }) - const WalletCreateTransactionRequest = IDL.Record({ - uid: IDL.Text, - name: IDL.Text, - network: Network, - batch_uid: IDL.Opt(IDL.Text), - }) - const MemberRemoveTransactionRequest = IDL.Record({ - member_id: IDL.Text, - batch_uid: IDL.Opt(IDL.Text), - }) - const MemberCreateTransactionRequest = IDL.Record({ - name: IDL.Text, - role: VaultRole, - member_id: IDL.Text, - batch_uid: IDL.Opt(IDL.Text), - }) - const TransferQuorumTransactionRequest = IDL.Record({ - memo: IDL.Opt(IDL.Text), - currency: Currency, - address: IDL.Text, - wallet: IDL.Text, - amount: IDL.Nat64, - }) - const MemberCreateTransactionRequestV2 = IDL.Record({ - name: IDL.Text, - role: VaultRole, - account: Account, - batch_uid: IDL.Opt(IDL.Text), - }) - const TransferTransactionRequest = IDL.Record({ - memo: IDL.Opt(IDL.Text), - currency: Currency, - address: IDL.Text, - wallet: IDL.Text, - amount: IDL.Nat64, - }) - const MemberUpdateRoleTransactionRequest = IDL.Record({ - role: VaultRole, - member_id: IDL.Text, - batch_uid: IDL.Opt(IDL.Text), - }) - const WalletUpdateNameTransactionRequest = IDL.Record({ - uid: IDL.Text, - name: IDL.Text, - batch_uid: IDL.Opt(IDL.Text), - }) - const PolicyUpdateTransactionRequest = IDL.Record({ - uid: IDL.Text, - member_threshold: IDL.Nat8, - amount_threshold: IDL.Nat64, - batch_uid: IDL.Opt(IDL.Text), - }) - const VersionUpgradeTransactionRequest = IDL.Record({ version: IDL.Text }) - const TopUpQuorumTransactionRequest = IDL.Record({ - currency: Currency, - wallet: IDL.Text, - amount: IDL.Nat64, - }) - const MemberExtendICRC1AccountRequest = IDL.Record({ - account: Account, - batch_uid: IDL.Opt(IDL.Text), - }) - const PolicyRemoveTransactionRequest = IDL.Record({ - uid: IDL.Text, - batch_uid: IDL.Opt(IDL.Text), - }) - const PolicyCreateTransactionRequest = IDL.Record({ - uid: IDL.Text, - member_threshold: IDL.Nat8, - amount_threshold: IDL.Nat64, - wallets: IDL.Vec(IDL.Text), - currency: Currency, - batch_uid: IDL.Opt(IDL.Text), - }) - const TransactionRequest = IDL.Variant({ - QuorumUpdateTransactionRequestV: QuorumUpdateTransactionRequest, - VaultNamingUpdateTransactionRequestV: VaultNamingUpdateTransactionRequest, - PurgeTransactionRequestV: IDL.Record({}), - ControllersUpdateTransactionRequestV: ControllersUpdateTransactionRequest, - MemberUpdateNameTransactionRequestV: MemberUpdateNameTransactionRequest, - TopUpTransactionRequestV: TopUpTransactionRequest, - TransferICRC1QuorumTransactionRequestV: TransferICRC1QuorumTransactionRequest, - WalletCreateTransactionRequestV: WalletCreateTransactionRequest, - MemberRemoveTransactionRequestV: MemberRemoveTransactionRequest, - MemberCreateTransactionRequestV: MemberCreateTransactionRequest, - TransferQuorumTransactionRequestV: TransferQuorumTransactionRequest, - MemberCreateTransactionRequestV2: MemberCreateTransactionRequestV2, - TransferTransactionRequestV: TransferTransactionRequest, - MemberUpdateRoleTransactionRequestV: MemberUpdateRoleTransactionRequest, - WalletUpdateNameTransactionRequestV: WalletUpdateNameTransactionRequest, - PolicyUpdateTransactionRequestV: PolicyUpdateTransactionRequest, - VersionUpgradeTransactionRequestV: VersionUpgradeTransactionRequest, - TopUpQuorumTransactionRequestV: TopUpQuorumTransactionRequest, - MemberExtendICRC1AccountRequestV: MemberExtendICRC1AccountRequest, - PolicyRemoveTransactionRequestV: PolicyRemoveTransactionRequest, - PolicyCreateTransactionRequestV: PolicyCreateTransactionRequest, - }) - return IDL.Service({ - approve: IDL.Func([IDL.Vec(TransactionApproveRequest)], [IDL.Vec(TransactionCandid)], []), - canister_balance: IDL.Func([], [IDL.Nat64], ["query"]), - execute: IDL.Func([], [], []), - get_controllers: IDL.Func([], [IDL.Vec(IDL.Principal)], []), - get_state: IDL.Func([IDL.Opt(IDL.Nat64)], [VaultState], ["query"]), - get_transactions_all: IDL.Func([], [IDL.Vec(TransactionCandid)], ["query"]), - get_trusted_origins_certified: IDL.Func( - [], - [ - IDL.Record({ - certificate: IDL.Vec(IDL.Nat8), - witness: IDL.Vec(IDL.Nat8), - response: IDL.Vec(IDL.Text), - }), - ], - ["query"] - ), - get_version: IDL.Func([], [IDL.Text], ["query"]), - remove_icrc1_canister: IDL.Func([IDL.Principal], [VaultState], []), - request_transaction: IDL.Func([IDL.Vec(TransactionRequest)], [IDL.Vec(TransactionCandid)], []), - store_icrc1_canister: IDL.Func([IDL.Principal, IDL.Opt(IDL.Principal)], [VaultState], []), - }) -} +export const idlFactory = ({ IDL } : any) => { + const Conf = IDL.Record({ + 'origins' : IDL.Vec(IDL.Text), + 'repo_canister' : IDL.Text, + }); + const TransactionState = IDL.Variant({ + 'Blocked' : IDL.Null, + 'Failed' : IDL.Null, + 'Approved' : IDL.Null, + 'Rejected' : IDL.Null, + 'Executed' : IDL.Null, + 'Purged' : IDL.Null, + 'Pending' : IDL.Null, + }); + const TransactionApproveRequest = IDL.Record({ + 'transaction_id' : IDL.Nat64, + 'state' : TransactionState, + }); + const VaultError = IDL.Variant({ + 'ControllersUpdateError' : IDL.Record({ 'message' : IDL.Text }), + 'WalletNotExists' : IDL.Null, + 'CouldNotDefinePolicy' : IDL.Null, + 'ThresholdAlreadyExists' : IDL.Null, + 'QuorumNotReachable' : IDL.Null, + 'CanisterReject' : IDL.Record({ 'message' : IDL.Text }), + 'MemberNotExists' : IDL.Null, + 'MemberAlreadyExists' : IDL.Null, + 'ThresholdDefineError' : IDL.Record({ 'message' : IDL.Text }), + 'UIDAlreadyExists' : IDL.Null, + 'PolicyNotExists' : IDL.Null, + }); + const Approve = IDL.Record({ + 'status' : TransactionState, + 'signer' : IDL.Text, + 'created_date' : IDL.Nat64, + }); + const BasicTransactionFields = IDL.Record({ + 'id' : IDL.Nat64, + 'threshold' : IDL.Opt(IDL.Nat8), + 'initiator' : IDL.Text, + 'modified_date' : IDL.Nat64, + 'memo' : IDL.Opt(IDL.Text), + 'error' : IDL.Opt(VaultError), + 'state' : TransactionState, + 'approves' : IDL.Vec(Approve), + 'is_vault_state' : IDL.Bool, + 'created_date' : IDL.Nat64, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const ControllersUpdateTransaction = IDL.Record({ + 'principals' : IDL.Vec(IDL.Principal), + 'common' : BasicTransactionFields, + 'current_controllers' : IDL.Vec(IDL.Principal), + }); + const Network = IDL.Variant({ + 'IC' : IDL.Null, + 'BTC' : IDL.Null, + 'ETH' : IDL.Null, + }); + const WalletCreateTransaction = IDL.Record({ + 'uid' : IDL.Text, + 'name' : IDL.Text, + 'network' : Network, + 'common' : BasicTransactionFields, + }); + const Currency = IDL.Variant({ 'ICP' : IDL.Null }); + const PolicyCreateTransaction = IDL.Record({ + 'uid' : IDL.Text, + 'member_threshold' : IDL.Nat8, + 'amount_threshold' : IDL.Nat64, + 'wallets' : IDL.Vec(IDL.Text), + 'currency' : Currency, + 'common' : BasicTransactionFields, + }); + const VaultRole = IDL.Variant({ 'Member' : IDL.Null, 'Admin' : IDL.Null }); + const MemberUpdateRoleTransaction = IDL.Record({ + 'role' : VaultRole, + 'member_id' : IDL.Text, + 'common' : BasicTransactionFields, + }); + const ICRC1CanistersRemoveTransaction = IDL.Record({ + 'ledger_canister' : IDL.Principal, + 'common' : BasicTransactionFields, + }); + const TopUpTransaction = IDL.Record({ + 'block_index' : IDL.Opt(IDL.Nat64), + 'currency' : Currency, + 'wallet' : IDL.Text, + 'common' : BasicTransactionFields, + 'amount' : IDL.Nat64, + 'policy' : IDL.Opt(IDL.Text), + }); + const TopUpQuorumTransaction = IDL.Record({ + 'block_index' : IDL.Opt(IDL.Nat64), + 'currency' : Currency, + 'wallet' : IDL.Text, + 'common' : BasicTransactionFields, + 'amount' : IDL.Nat64, + }); + const ICRC1CanistersAddTransaction = IDL.Record({ + 'index_canister' : IDL.Opt(IDL.Principal), + 'ledger_canister' : IDL.Principal, + 'common' : BasicTransactionFields, + }); + const VaultNamingUpdateTransaction = IDL.Record({ + 'name' : IDL.Opt(IDL.Text), + 'description' : IDL.Opt(IDL.Text), + 'common' : BasicTransactionFields, + }); + const TransferTransaction = IDL.Record({ + 'block_index' : IDL.Opt(IDL.Nat64), + 'currency' : Currency, + 'address' : IDL.Text, + 'wallet' : IDL.Text, + 'common' : BasicTransactionFields, + 'amount' : IDL.Nat64, + 'policy' : IDL.Opt(IDL.Text), + }); + const PolicyRemoveTransaction = IDL.Record({ + 'uid' : IDL.Text, + 'common' : BasicTransactionFields, + }); + const Account = IDL.Record({ + 'owner' : IDL.Principal, + 'subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)), + }); + const MemberExtendICRC1AccountTransaction = IDL.Record({ + 'account' : Account, + 'common' : BasicTransactionFields, + }); + const PolicyUpdateTransaction = IDL.Record({ + 'uid' : IDL.Text, + 'member_threshold' : IDL.Nat8, + 'amount_threshold' : IDL.Nat64, + 'common' : BasicTransactionFields, + }); + const TransferICRC1QuorumTransaction = IDL.Record({ + 'to_principal' : IDL.Principal, + 'block_index' : IDL.Opt(IDL.Nat), + 'to_subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'ledger_id' : IDL.Principal, + 'wallet' : IDL.Text, + 'common' : BasicTransactionFields, + 'amount' : IDL.Nat64, + }); + const MemberCreateTransaction = IDL.Record({ + 'name' : IDL.Text, + 'role' : VaultRole, + 'member_id' : IDL.Text, + 'common' : BasicTransactionFields, + }); + const MemberUpdateNameTransaction = IDL.Record({ + 'name' : IDL.Text, + 'member_id' : IDL.Text, + 'common' : BasicTransactionFields, + }); + const VersionUpgradeTransaction = IDL.Record({ + 'version' : IDL.Text, + 'initial_version' : IDL.Text, + 'common' : BasicTransactionFields, + }); + const PurgeTransaction = IDL.Record({ 'common' : BasicTransactionFields }); + const TransferQuorumTransaction = IDL.Record({ + 'block_index' : IDL.Opt(IDL.Nat64), + 'currency' : Currency, + 'address' : IDL.Text, + 'wallet' : IDL.Text, + 'common' : BasicTransactionFields, + 'amount' : IDL.Nat64, + }); + const QuorumUpdateTransaction = IDL.Record({ + 'common' : BasicTransactionFields, + 'quorum' : IDL.Nat8, + }); + const MemberCreateTransactionV2 = IDL.Record({ + 'name' : IDL.Text, + 'role' : VaultRole, + 'account' : Account, + 'common' : BasicTransactionFields, + }); + const WalletUpdateNameTransaction = IDL.Record({ + 'uid' : IDL.Text, + 'name' : IDL.Text, + 'common' : BasicTransactionFields, + }); + const MemberRemoveTransaction = IDL.Record({ + 'member_id' : IDL.Text, + 'common' : BasicTransactionFields, + }); + const TransactionCandid = IDL.Variant({ + 'ControllersUpdateTransactionV' : ControllersUpdateTransaction, + 'WalletCreateTransactionV' : WalletCreateTransaction, + 'PolicyCreateTransactionV' : PolicyCreateTransaction, + 'MemberUpdateRoleTransactionV' : MemberUpdateRoleTransaction, + 'ICRC1CanistersRemoveTransactionV' : ICRC1CanistersRemoveTransaction, + 'TopUpTransactionV' : TopUpTransaction, + 'TopUpQuorumTransactionV' : TopUpQuorumTransaction, + 'ICRC1CanistersAddTransactionV' : ICRC1CanistersAddTransaction, + 'VaultNamingUpdateTransactionV' : VaultNamingUpdateTransaction, + 'TransferTransactionV' : TransferTransaction, + 'PolicyRemoveTransactionV' : PolicyRemoveTransaction, + 'MemberExtendICRC1AccountTransactionV' : MemberExtendICRC1AccountTransaction, + 'PolicyUpdateTransactionV' : PolicyUpdateTransaction, + 'TransferICRC1QuorumTransactionV' : TransferICRC1QuorumTransaction, + 'MemberCreateTransactionV' : MemberCreateTransaction, + 'MemberUpdateNameTransactionV' : MemberUpdateNameTransaction, + 'UpgradeTransactionV' : VersionUpgradeTransaction, + 'PurgeTransactionV' : PurgeTransaction, + 'TransferQuorumTransactionV' : TransferQuorumTransaction, + 'QuorumUpdateTransactionV' : QuorumUpdateTransaction, + 'MemberCreateTransactionV2' : MemberCreateTransactionV2, + 'WalletUpdateNameTransactionV' : WalletUpdateNameTransaction, + 'MemberRemoveTransactionV' : MemberRemoveTransaction, + }); + const Member = IDL.Record({ + 'modified_date' : IDL.Nat64, + 'name' : IDL.Text, + 'role' : VaultRole, + 'account' : IDL.Opt(Account), + 'member_id' : IDL.Text, + 'created_date' : IDL.Nat64, + }); + const ICRC1 = IDL.Record({ + 'ledger' : IDL.Principal, + 'index' : IDL.Opt(IDL.Principal), + }); + const Wallet = IDL.Record({ + 'uid' : IDL.Text, + 'modified_date' : IDL.Nat64, + 'name' : IDL.Text, + 'network' : Network, + 'created_date' : IDL.Nat64, + }); + const Quorum = IDL.Record({ + 'modified_date' : IDL.Nat64, + 'quorum' : IDL.Nat8, + }); + const Policy = IDL.Record({ + 'uid' : IDL.Text, + 'member_threshold' : IDL.Nat8, + 'modified_date' : IDL.Nat64, + 'amount_threshold' : IDL.Nat64, + 'wallets' : IDL.Vec(IDL.Text), + 'currency' : Currency, + 'created_date' : IDL.Nat64, + }); + const VaultState = IDL.Record({ + 'members' : IDL.Vec(Member), + 'name' : IDL.Opt(IDL.Text), + 'description' : IDL.Opt(IDL.Text), + 'icrc1_canisters' : IDL.Vec(ICRC1), + 'wallets' : IDL.Vec(Wallet), + 'quorum' : Quorum, + 'policies' : IDL.Vec(Policy), + }); + const ICRC1CanistersRemoveTransactionRequest = IDL.Record({ + 'ledger_canister' : IDL.Principal, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const QuorumUpdateTransactionRequest = IDL.Record({ + 'quorum' : IDL.Nat8, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const VaultNamingUpdateTransactionRequest = IDL.Record({ + 'name' : IDL.Opt(IDL.Text), + 'description' : IDL.Opt(IDL.Text), + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const ICRC1CanistersAddTransactionRequest = IDL.Record({ + 'index_canister' : IDL.Opt(IDL.Principal), + 'ledger_canister' : IDL.Principal, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const ControllersUpdateTransactionRequest = IDL.Record({ + 'principals' : IDL.Vec(IDL.Principal), + }); + const MemberUpdateNameTransactionRequest = IDL.Record({ + 'name' : IDL.Text, + 'member_id' : IDL.Text, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const TopUpTransactionRequest = IDL.Record({ + 'currency' : Currency, + 'wallet' : IDL.Text, + 'amount' : IDL.Nat64, + }); + const TransferICRC1QuorumTransactionRequest = IDL.Record({ + 'to_principal' : IDL.Principal, + 'to_subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'memo' : IDL.Opt(IDL.Text), + 'ledger_id' : IDL.Principal, + 'wallet' : IDL.Text, + 'amount' : IDL.Nat64, + }); + const WalletCreateTransactionRequest = IDL.Record({ + 'uid' : IDL.Text, + 'name' : IDL.Text, + 'network' : Network, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const MemberRemoveTransactionRequest = IDL.Record({ + 'member_id' : IDL.Text, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const MemberCreateTransactionRequest = IDL.Record({ + 'name' : IDL.Text, + 'role' : VaultRole, + 'member_id' : IDL.Text, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const TransferTransactionRequest = IDL.Record({ + 'memo' : IDL.Opt(IDL.Text), + 'currency' : Currency, + 'address' : IDL.Text, + 'wallet' : IDL.Text, + 'amount' : IDL.Nat64, + }); + const MemberCreateTransactionRequestV2 = IDL.Record({ + 'name' : IDL.Text, + 'role' : VaultRole, + 'account' : Account, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const MemberUpdateRoleTransactionRequest = IDL.Record({ + 'role' : VaultRole, + 'member_id' : IDL.Text, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const WalletUpdateNameTransactionRequest = IDL.Record({ + 'uid' : IDL.Text, + 'name' : IDL.Text, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const PolicyUpdateTransactionRequest = IDL.Record({ + 'uid' : IDL.Text, + 'member_threshold' : IDL.Nat8, + 'amount_threshold' : IDL.Nat64, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const VersionUpgradeTransactionRequest = IDL.Record({ 'version' : IDL.Text }); + const MemberExtendICRC1AccountRequest = IDL.Record({ + 'account' : Account, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const PolicyRemoveTransactionRequest = IDL.Record({ + 'uid' : IDL.Text, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const PolicyCreateTransactionRequest = IDL.Record({ + 'uid' : IDL.Text, + 'member_threshold' : IDL.Nat8, + 'amount_threshold' : IDL.Nat64, + 'wallets' : IDL.Vec(IDL.Text), + 'currency' : Currency, + 'batch_uid' : IDL.Opt(IDL.Text), + }); + const TransactionRequest = IDL.Variant({ + 'ICRC1CanistersRemoveTransactionRequestV' : ICRC1CanistersRemoveTransactionRequest, + 'QuorumUpdateTransactionRequestV' : QuorumUpdateTransactionRequest, + 'VaultNamingUpdateTransactionRequestV' : VaultNamingUpdateTransactionRequest, + 'PurgeTransactionRequestV' : IDL.Record({}), + 'ICRC1CanistersAddTransactionRequestV' : ICRC1CanistersAddTransactionRequest, + 'ControllersUpdateTransactionRequestV' : ControllersUpdateTransactionRequest, + 'MemberUpdateNameTransactionRequestV' : MemberUpdateNameTransactionRequest, + 'TopUpTransactionRequestV' : TopUpTransactionRequest, + 'TransferICRC1QuorumTransactionRequestV' : TransferICRC1QuorumTransactionRequest, + 'WalletCreateTransactionRequestV' : WalletCreateTransactionRequest, + 'MemberRemoveTransactionRequestV' : MemberRemoveTransactionRequest, + 'MemberCreateTransactionRequestV' : MemberCreateTransactionRequest, + 'TransferQuorumTransactionRequestV' : TransferTransactionRequest, + 'MemberCreateTransactionRequestV2' : MemberCreateTransactionRequestV2, + 'TransferTransactionRequestV' : TransferTransactionRequest, + 'MemberUpdateRoleTransactionRequestV' : MemberUpdateRoleTransactionRequest, + 'WalletUpdateNameTransactionRequestV' : WalletUpdateNameTransactionRequest, + 'PolicyUpdateTransactionRequestV' : PolicyUpdateTransactionRequest, + 'VersionUpgradeTransactionRequestV' : VersionUpgradeTransactionRequest, + 'TopUpQuorumTransactionRequestV' : TopUpTransactionRequest, + 'MemberExtendICRC1AccountRequestV' : MemberExtendICRC1AccountRequest, + 'PolicyRemoveTransactionRequestV' : PolicyRemoveTransactionRequest, + 'PolicyCreateTransactionRequestV' : PolicyCreateTransactionRequest, + }); + return IDL.Service({ + 'approve' : IDL.Func( + [IDL.Vec(TransactionApproveRequest)], + [IDL.Vec(TransactionCandid)], + [], + ), + 'canister_balance' : IDL.Func([], [IDL.Nat64], ['query']), + 'execute' : IDL.Func([], [], []), + 'get_controllers' : IDL.Func([], [IDL.Vec(IDL.Principal)], []), + 'get_state' : IDL.Func([IDL.Opt(IDL.Nat64)], [VaultState], ['query']), + 'get_transactions_all' : IDL.Func( + [], + [IDL.Vec(TransactionCandid)], + ['query'], + ), + 'get_trusted_origins_certified' : IDL.Func( + [], + [ + IDL.Record({ + 'certificate' : IDL.Vec(IDL.Nat8), + 'witness' : IDL.Vec(IDL.Nat8), + 'response' : IDL.Vec(IDL.Text), + }), + ], + ['query'], + ), + 'get_version' : IDL.Func([], [IDL.Text], ['query']), + 'request_transaction' : IDL.Func( + [IDL.Vec(TransactionRequest)], + [IDL.Vec(TransactionCandid)], + [], + ), + }); +}; diff --git a/packages/vaults/src/idl/service_vault.ts b/packages/vaults/src/idl/service_vault.ts index 0e640533..52627464 100644 --- a/packages/vaults/src/idl/service_vault.ts +++ b/packages/vaults/src/idl/service_vault.ts @@ -1,410 +1,412 @@ -import type { Principal } from "@dfinity/principal" -import type { ActorMethod } from "@dfinity/agent" +import type { Principal } from '@dfinity/principal'; +import type { ActorMethod } from '@dfinity/agent'; +import type { IDL } from '@dfinity/candid'; export interface Account { - owner: Principal - subaccount: [] | [SubAccount] + 'owner' : Principal, + 'subaccount' : [] | [Uint8Array | number[]], } export interface Approve { - status: TransactionState - signer: string - created_date: bigint + 'status' : TransactionState, + 'signer' : string, + 'created_date' : bigint, } export interface BasicTransactionFields { - id: bigint - threshold: [] | [number] - initiator: string - modified_date: bigint - memo: [] | [string] - error: [] | [VaultError] - state: TransactionState - approves: Array - is_vault_state: boolean - created_date: bigint - batch_uid: [] | [string] -} -export interface Conf { - origins: Array - repo_canister: string -} + 'id' : bigint, + 'threshold' : [] | [number], + 'initiator' : string, + 'modified_date' : bigint, + 'memo' : [] | [string], + 'error' : [] | [VaultError], + 'state' : TransactionState, + 'approves' : Array, + 'is_vault_state' : boolean, + 'created_date' : bigint, + 'batch_uid' : [] | [string], +} +export interface Conf { 'origins' : Array, 'repo_canister' : string } export interface ControllersUpdateTransaction { - principals: Array - common: BasicTransactionFields - current_controllers: Array + 'principals' : Array, + 'common' : BasicTransactionFields, + 'current_controllers' : Array, } export interface ControllersUpdateTransactionRequest { - principals: Array + 'principals' : Array, +} +export type Currency = { 'ICP' : null }; +export interface ICRC1 { 'ledger' : Principal, 'index' : [] | [Principal] } +export interface ICRC1CanistersAddTransaction { + 'index_canister' : [] | [Principal], + 'ledger_canister' : Principal, + 'common' : BasicTransactionFields, +} +export interface ICRC1CanistersAddTransactionRequest { + 'index_canister' : [] | [Principal], + 'ledger_canister' : Principal, + 'batch_uid' : [] | [string], } -export type Currency = { ICP: null } -export interface ICRC1 { - ledger: Principal - index: [] | [Principal] +export interface ICRC1CanistersRemoveTransaction { + 'ledger_canister' : Principal, + 'common' : BasicTransactionFields, +} +export interface ICRC1CanistersRemoveTransactionRequest { + 'ledger_canister' : Principal, + 'batch_uid' : [] | [string], } export interface Member { - modified_date: bigint - name: string - role: VaultRole - account: [] | [Account] - member_id: string - created_date: bigint + 'modified_date' : bigint, + 'name' : string, + 'role' : VaultRole, + 'account' : [] | [Account], + 'member_id' : string, + 'created_date' : bigint, } export interface MemberCreateTransaction { - name: string - role: VaultRole - member_id: string - common: BasicTransactionFields + 'name' : string, + 'role' : VaultRole, + 'member_id' : string, + 'common' : BasicTransactionFields, } export interface MemberCreateTransactionRequest { - name: string - role: VaultRole - member_id: string - batch_uid: [] | [string] + 'name' : string, + 'role' : VaultRole, + 'member_id' : string, + 'batch_uid' : [] | [string], } export interface MemberCreateTransactionRequestV2 { - name: string - role: VaultRole - account: Account - batch_uid: [] | [string] + 'name' : string, + 'role' : VaultRole, + 'account' : Account, + 'batch_uid' : [] | [string], } export interface MemberCreateTransactionV2 { - name: string - role: VaultRole - account: Account - common: BasicTransactionFields + 'name' : string, + 'role' : VaultRole, + 'account' : Account, + 'common' : BasicTransactionFields, } export interface MemberExtendICRC1AccountRequest { - account: Account - batch_uid: [] | [string] + 'account' : Account, + 'batch_uid' : [] | [string], } export interface MemberExtendICRC1AccountTransaction { - account: Account - batch_uid: [] | [string] - common: BasicTransactionFields + 'account' : Account, + 'common' : BasicTransactionFields, } export interface MemberRemoveTransaction { - member_id: string - common: BasicTransactionFields + 'member_id' : string, + 'common' : BasicTransactionFields, } export interface MemberRemoveTransactionRequest { - member_id: string - batch_uid: [] | [string] + 'member_id' : string, + 'batch_uid' : [] | [string], } export interface MemberUpdateNameTransaction { - name: string - member_id: string - common: BasicTransactionFields + 'name' : string, + 'member_id' : string, + 'common' : BasicTransactionFields, } export interface MemberUpdateNameTransactionRequest { - name: string - member_id: string - batch_uid: [] | [string] + 'name' : string, + 'member_id' : string, + 'batch_uid' : [] | [string], } export interface MemberUpdateRoleTransaction { - role: VaultRole - member_id: string - common: BasicTransactionFields + 'role' : VaultRole, + 'member_id' : string, + 'common' : BasicTransactionFields, } export interface MemberUpdateRoleTransactionRequest { - role: VaultRole - member_id: string - batch_uid: [] | [string] + 'role' : VaultRole, + 'member_id' : string, + 'batch_uid' : [] | [string], } -export type Network = { IC: null } | { BTC: null } | { ETH: null } +export type Network = { 'IC' : null } | + { 'BTC' : null } | + { 'ETH' : null }; export interface Policy { - uid: string - member_threshold: number - modified_date: bigint - amount_threshold: bigint - wallets: Array - currency: Currency - created_date: bigint + 'uid' : string, + 'member_threshold' : number, + 'modified_date' : bigint, + 'amount_threshold' : bigint, + 'wallets' : Array, + 'currency' : Currency, + 'created_date' : bigint, } export interface PolicyCreateTransaction { - uid: string - member_threshold: number - amount_threshold: bigint - wallets: Array - currency: Currency - common: BasicTransactionFields + 'uid' : string, + 'member_threshold' : number, + 'amount_threshold' : bigint, + 'wallets' : Array, + 'currency' : Currency, + 'common' : BasicTransactionFields, } export interface PolicyCreateTransactionRequest { - uid: string - member_threshold: number - amount_threshold: bigint - wallets: Array - currency: Currency - batch_uid: [] | [string] + 'uid' : string, + 'member_threshold' : number, + 'amount_threshold' : bigint, + 'wallets' : Array, + 'currency' : Currency, + 'batch_uid' : [] | [string], } export interface PolicyRemoveTransaction { - uid: string - common: BasicTransactionFields + 'uid' : string, + 'common' : BasicTransactionFields, } export interface PolicyRemoveTransactionRequest { - uid: string - batch_uid: [] | [string] + 'uid' : string, + 'batch_uid' : [] | [string], } export interface PolicyUpdateTransaction { - uid: string - member_threshold: number - amount_threshold: bigint - common: BasicTransactionFields + 'uid' : string, + 'member_threshold' : number, + 'amount_threshold' : bigint, + 'common' : BasicTransactionFields, } export interface PolicyUpdateTransactionRequest { - uid: string - member_threshold: number - amount_threshold: bigint - batch_uid: [] | [string] -} -export interface PurgeTransaction { - common: BasicTransactionFields -} -export interface Quorum { - modified_date: bigint - quorum: number + 'uid' : string, + 'member_threshold' : number, + 'amount_threshold' : bigint, + 'batch_uid' : [] | [string], } +export interface PurgeTransaction { 'common' : BasicTransactionFields } +export interface Quorum { 'modified_date' : bigint, 'quorum' : number } export interface QuorumUpdateTransaction { - common: BasicTransactionFields - quorum: number + 'common' : BasicTransactionFields, + 'quorum' : number, } export interface QuorumUpdateTransactionRequest { - quorum: number - batch_uid: [] | [string] + 'quorum' : number, + 'batch_uid' : [] | [string], } export type SubAccount = Uint8Array | number[] -export type Subaccount = [] | [Uint8Array | number[]] export interface TopUpQuorumTransaction { - block_index: [] | [bigint] - currency: Currency - wallet: string - common: BasicTransactionFields - amount: bigint -} -export interface TopUpQuorumTransactionRequest { - currency: Currency - wallet: string - amount: bigint + 'block_index' : [] | [bigint], + 'currency' : Currency, + 'wallet' : string, + 'common' : BasicTransactionFields, + 'amount' : bigint, } export interface TopUpTransaction { - block_index: [] | [bigint] - currency: Currency - wallet: string - common: BasicTransactionFields - amount: bigint - policy: [] | [string] + 'block_index' : [] | [bigint], + 'currency' : Currency, + 'wallet' : string, + 'common' : BasicTransactionFields, + 'amount' : bigint, + 'policy' : [] | [string], } export interface TopUpTransactionRequest { - currency: Currency - wallet: string - amount: bigint + 'currency' : Currency, + 'wallet' : string, + 'amount' : bigint, } export interface TransactionApproveRequest { - transaction_id: bigint - state: TransactionState -} -export type TransactionCandid = - | { - ControllersUpdateTransactionV: ControllersUpdateTransaction - } - | { WalletCreateTransactionV: WalletCreateTransaction } - | { PolicyCreateTransactionV: PolicyCreateTransaction } - | { MemberUpdateRoleTransactionV: MemberUpdateRoleTransaction } - | { TopUpTransactionV: TopUpTransaction } - | { TopUpQuorumTransactionV: TopUpQuorumTransaction } - | { VaultNamingUpdateTransactionV: VaultNamingUpdateTransaction } - | { TransferTransactionV: TransferTransaction } - | { PolicyRemoveTransactionV: PolicyRemoveTransaction } - | { - MemberExtendICRC1AccountTransactionV: MemberExtendICRC1AccountTransaction - } - | { PolicyUpdateTransactionV: PolicyUpdateTransaction } - | { TransferICRC1QuorumTransactionV: TransferICRC1QuorumTransaction } - | { MemberCreateTransactionV: MemberCreateTransaction } - | { MemberUpdateNameTransactionV: MemberUpdateNameTransaction } - | { UpgradeTransactionV: VersionUpgradeTransaction } - | { PurgeTransactionV: PurgeTransaction } - | { TransferQuorumTransactionV: TransferQuorumTransaction } - | { QuorumUpdateTransactionV: QuorumUpdateTransaction } - | { MemberCreateTransactionV2: MemberCreateTransactionV2 } - | { WalletUpdateNameTransactionV: WalletUpdateNameTransaction } - | { MemberRemoveTransactionV: MemberRemoveTransaction } -export type TransactionRequest = - | { - QuorumUpdateTransactionRequestV: QuorumUpdateTransactionRequest - } - | { - VaultNamingUpdateTransactionRequestV: VaultNamingUpdateTransactionRequest - } - | { PurgeTransactionRequestV: object } - | { - ControllersUpdateTransactionRequestV: ControllersUpdateTransactionRequest - } - | { - MemberUpdateNameTransactionRequestV: MemberUpdateNameTransactionRequest - } - | { TopUpTransactionRequestV: TopUpTransactionRequest } - | { - TransferICRC1QuorumTransactionRequestV: TransferICRC1QuorumTransactionRequest - } - | { WalletCreateTransactionRequestV: WalletCreateTransactionRequest } - | { MemberRemoveTransactionRequestV: MemberRemoveTransactionRequest } - | { MemberCreateTransactionRequestV: MemberCreateTransactionRequest } - | { TransferQuorumTransactionRequestV: TransferQuorumTransactionRequest } - | { MemberCreateTransactionRequestV2: MemberCreateTransactionRequestV2 } - | { TransferTransactionRequestV: TransferTransactionRequest } - | { - MemberUpdateRoleTransactionRequestV: MemberUpdateRoleTransactionRequest - } - | { - WalletUpdateNameTransactionRequestV: WalletUpdateNameTransactionRequest - } - | { PolicyUpdateTransactionRequestV: PolicyUpdateTransactionRequest } - | { VersionUpgradeTransactionRequestV: VersionUpgradeTransactionRequest } - | { TopUpQuorumTransactionRequestV: TopUpQuorumTransactionRequest } - | { MemberExtendICRC1AccountRequestV: MemberExtendICRC1AccountRequest } - | { PolicyRemoveTransactionRequestV: PolicyRemoveTransactionRequest } - | { PolicyCreateTransactionRequestV: PolicyCreateTransactionRequest } -export type TransactionState = - | { Blocked: null } - | { Failed: null } - | { Approved: null } - | { Rejected: null } - | { Executed: null } - | { Purged: null } - | { Pending: null } + 'transaction_id' : bigint, + 'state' : TransactionState, +} +export type TransactionCandid = { + 'ControllersUpdateTransactionV' : ControllersUpdateTransaction +} | + { 'WalletCreateTransactionV' : WalletCreateTransaction } | + { 'PolicyCreateTransactionV' : PolicyCreateTransaction } | + { 'MemberUpdateRoleTransactionV' : MemberUpdateRoleTransaction } | + { 'ICRC1CanistersRemoveTransactionV' : ICRC1CanistersRemoveTransaction } | + { 'TopUpTransactionV' : TopUpTransaction } | + { 'TopUpQuorumTransactionV' : TopUpQuorumTransaction } | + { 'ICRC1CanistersAddTransactionV' : ICRC1CanistersAddTransaction } | + { 'VaultNamingUpdateTransactionV' : VaultNamingUpdateTransaction } | + { 'TransferTransactionV' : TransferTransaction } | + { 'PolicyRemoveTransactionV' : PolicyRemoveTransaction } | + { + 'MemberExtendICRC1AccountTransactionV' : MemberExtendICRC1AccountTransaction + } | + { 'PolicyUpdateTransactionV' : PolicyUpdateTransaction } | + { 'TransferICRC1QuorumTransactionV' : TransferICRC1QuorumTransaction } | + { 'MemberCreateTransactionV' : MemberCreateTransaction } | + { 'MemberUpdateNameTransactionV' : MemberUpdateNameTransaction } | + { 'UpgradeTransactionV' : VersionUpgradeTransaction } | + { 'PurgeTransactionV' : PurgeTransaction } | + { 'TransferQuorumTransactionV' : TransferQuorumTransaction } | + { 'QuorumUpdateTransactionV' : QuorumUpdateTransaction } | + { 'MemberCreateTransactionV2' : MemberCreateTransactionV2 } | + { 'WalletUpdateNameTransactionV' : WalletUpdateNameTransaction } | + { 'MemberRemoveTransactionV' : MemberRemoveTransaction }; +export type TransactionRequest = { + 'ICRC1CanistersRemoveTransactionRequestV' : ICRC1CanistersRemoveTransactionRequest +} | + { 'QuorumUpdateTransactionRequestV' : QuorumUpdateTransactionRequest } | + { + 'VaultNamingUpdateTransactionRequestV' : VaultNamingUpdateTransactionRequest + } | + { 'PurgeTransactionRequestV' : {} } | + { + 'ICRC1CanistersAddTransactionRequestV' : ICRC1CanistersAddTransactionRequest + } | + { + 'ControllersUpdateTransactionRequestV' : ControllersUpdateTransactionRequest + } | + { + 'MemberUpdateNameTransactionRequestV' : MemberUpdateNameTransactionRequest + } | + { 'TopUpTransactionRequestV' : TopUpTransactionRequest } | + { + 'TransferICRC1QuorumTransactionRequestV' : TransferICRC1QuorumTransactionRequest + } | + { 'WalletCreateTransactionRequestV' : WalletCreateTransactionRequest } | + { 'MemberRemoveTransactionRequestV' : MemberRemoveTransactionRequest } | + { 'MemberCreateTransactionRequestV' : MemberCreateTransactionRequest } | + { 'TransferQuorumTransactionRequestV' : TransferTransactionRequest } | + { 'MemberCreateTransactionRequestV2' : MemberCreateTransactionRequestV2 } | + { 'TransferTransactionRequestV' : TransferTransactionRequest } | + { + 'MemberUpdateRoleTransactionRequestV' : MemberUpdateRoleTransactionRequest + } | + { + 'WalletUpdateNameTransactionRequestV' : WalletUpdateNameTransactionRequest + } | + { 'PolicyUpdateTransactionRequestV' : PolicyUpdateTransactionRequest } | + { 'VersionUpgradeTransactionRequestV' : VersionUpgradeTransactionRequest } | + { 'TopUpQuorumTransactionRequestV' : TopUpTransactionRequest } | + { 'MemberExtendICRC1AccountRequestV' : MemberExtendICRC1AccountRequest } | + { 'PolicyRemoveTransactionRequestV' : PolicyRemoveTransactionRequest } | + { 'PolicyCreateTransactionRequestV' : PolicyCreateTransactionRequest }; +export type TransactionState = { 'Blocked' : null } | + { 'Failed' : null } | + { 'Approved' : null } | + { 'Rejected' : null } | + { 'Executed' : null } | + { 'Purged' : null } | + { 'Pending' : null }; export interface TransferICRC1QuorumTransaction { - to_principal: Principal - block_index: [] | [number] - to_subaccount: [] | [Uint8Array | number[]] - ledger_id: Principal - wallet: string - common: BasicTransactionFields - amount: bigint + 'to_principal' : Principal, + 'block_index' : [] | [bigint], + 'to_subaccount' : [] | [Uint8Array | number[]], + 'ledger_id' : Principal, + 'wallet' : string, + 'common' : BasicTransactionFields, + 'amount' : bigint, } export interface TransferICRC1QuorumTransactionRequest { - to_principal: Principal - to_subaccount: [] | [Uint8Array | number[]] - memo: [] | [string] - ledger_id: Principal - wallet: string - amount: bigint + 'to_principal' : Principal, + 'to_subaccount' : [] | [Uint8Array | number[]], + 'memo' : [] | [string], + 'ledger_id' : Principal, + 'wallet' : string, + 'amount' : bigint, } export interface TransferQuorumTransaction { - block_index: [] | [bigint] - currency: Currency - address: string - wallet: string - common: BasicTransactionFields - amount: bigint -} -export interface TransferQuorumTransactionRequest { - memo: [] | [string] - currency: Currency - address: string - wallet: string - amount: bigint + 'block_index' : [] | [bigint], + 'currency' : Currency, + 'address' : string, + 'wallet' : string, + 'common' : BasicTransactionFields, + 'amount' : bigint, } export interface TransferTransaction { - block_index: [] | [bigint] - currency: Currency - address: string - wallet: string - common: BasicTransactionFields - amount: bigint - policy: [] | [string] + 'block_index' : [] | [bigint], + 'currency' : Currency, + 'address' : string, + 'wallet' : string, + 'common' : BasicTransactionFields, + 'amount' : bigint, + 'policy' : [] | [string], } export interface TransferTransactionRequest { - memo: [] | [string] - currency: Currency - address: string - wallet: string - amount: bigint -} -export type VaultError = - | { ControllersUpdateError: { message: string } } - | { WalletNotExists: null } - | { CouldNotDefinePolicy: null } - | { ThresholdAlreadyExists: null } - | { QuorumNotReachable: null } - | { CanisterReject: { message: string } } - | { MemberNotExists: null } - | { MemberAlreadyExists: null } - | { ThresholdDefineError: { message: string } } - | { UIDAlreadyExists: null } - | { PolicyNotExists: null } + 'memo' : [] | [string], + 'currency' : Currency, + 'address' : string, + 'wallet' : string, + 'amount' : bigint, +} +export type VaultError = { 'ControllersUpdateError' : { 'message' : string } } | + { 'WalletNotExists' : null } | + { 'CouldNotDefinePolicy' : null } | + { 'ThresholdAlreadyExists' : null } | + { 'QuorumNotReachable' : null } | + { 'CanisterReject' : { 'message' : string } } | + { 'MemberNotExists' : null } | + { 'MemberAlreadyExists' : null } | + { 'ThresholdDefineError' : { 'message' : string } } | + { 'UIDAlreadyExists' : null } | + { 'PolicyNotExists' : null }; export interface VaultNamingUpdateTransaction { - name: [] | [string] - description: [] | [string] - common: BasicTransactionFields + 'name' : [] | [string], + 'description' : [] | [string], + 'common' : BasicTransactionFields, } export interface VaultNamingUpdateTransactionRequest { - name: [] | [string] - description: [] | [string] - batch_uid: [] | [string] + 'name' : [] | [string], + 'description' : [] | [string], + 'batch_uid' : [] | [string], } -export type VaultRole = { Member: null } | { Admin: null } +export type VaultRole = { 'Member' : null } | + { 'Admin' : null }; export interface VaultState { - members: Array - name: [] | [string] - description: [] | [string] - icrc1_canisters: Array - wallets: Array - quorum: Quorum - policies: Array + 'members' : Array, + 'name' : [] | [string], + 'description' : [] | [string], + 'icrc1_canisters' : Array, + 'wallets' : Array, + 'quorum' : Quorum, + 'policies' : Array, } export interface VersionUpgradeTransaction { - version: string - initial_version: string - common: BasicTransactionFields -} -export interface VersionUpgradeTransactionRequest { - version: string + 'version' : string, + 'initial_version' : string, + 'common' : BasicTransactionFields, } +export interface VersionUpgradeTransactionRequest { 'version' : string } export interface Wallet { - uid: string - modified_date: bigint - name: string - network: Network - created_date: bigint + 'uid' : string, + 'modified_date' : bigint, + 'name' : string, + 'network' : Network, + 'created_date' : bigint, } export interface WalletCreateTransaction { - uid: string - name: string - network: Network - common: BasicTransactionFields + 'uid' : string, + 'name' : string, + 'network' : Network, + 'common' : BasicTransactionFields, } export interface WalletCreateTransactionRequest { - uid: string - name: string - network: Network - batch_uid: [] | [string] + 'uid' : string, + 'name' : string, + 'network' : Network, + 'batch_uid' : [] | [string], } export interface WalletUpdateNameTransaction { - uid: string - name: string - common: BasicTransactionFields + 'uid' : string, + 'name' : string, + 'common' : BasicTransactionFields, } export interface WalletUpdateNameTransactionRequest { - uid: string - name: string - batch_uid: [] | [string] + 'uid' : string, + 'name' : string, + 'batch_uid' : [] | [string], } export interface _SERVICE { - approve: ActorMethod<[Array], Array> - canister_balance: ActorMethod<[], bigint> - execute: ActorMethod<[], undefined> - get_controllers: ActorMethod<[], Array> - get_state: ActorMethod<[[] | [bigint]], VaultState> - get_transactions_all: ActorMethod<[], Array> - get_trusted_origins_certified: ActorMethod< - [], - { - certificate: Uint8Array | number[] - witness: Uint8Array | number[] - response: Array - } - > - get_version: ActorMethod<[], string> - remove_icrc1_canister: ActorMethod<[Principal], VaultState> - request_transaction: ActorMethod<[Array], Array> - store_icrc1_canister: ActorMethod<[Principal, [] | [Principal]], VaultState> -} + 'approve' : ActorMethod< + [Array], + Array + >, + 'canister_balance' : ActorMethod<[], bigint>, + 'execute' : ActorMethod<[], undefined>, + 'get_controllers' : ActorMethod<[], Array>, + 'get_state' : ActorMethod<[[] | [bigint]], VaultState>, + 'get_transactions_all' : ActorMethod<[], Array>, + 'get_trusted_origins_certified' : ActorMethod< + [], + { + 'certificate' : Uint8Array | number[], + 'witness' : Uint8Array | number[], + 'response' : Array, + } + >, + 'get_version' : ActorMethod<[], string>, + 'request_transaction' : ActorMethod< + [Array], + Array + >, +} +export declare const idlFactory: IDL.InterfaceFactory; diff --git a/packages/vaults/src/manager/vault_manager.ts b/packages/vaults/src/manager/vault_manager.ts index 6cc34225..072f3a02 100644 --- a/packages/vaults/src/manager/vault_manager.ts +++ b/packages/vaults/src/manager/vault_manager.ts @@ -51,30 +51,6 @@ export class VaultManager implements VaultManagerI { this.identity = identity } - /** - * Method for adding a personal list of ICRC-1 canisters by the user. - * Returns the updated vault state. - * Needed for displaying the balance of ICRC-1 tokens. - * @param ledger Ledger ICRC-1 canister to be added. - * @param index Optional index ICRC-1 canister to be added. - */ - async addICRC1Canister(ledger: Principal, index?: Principal): Promise { - const index_candid: [] | [Principal] = index === undefined ? [] : [index] - const vault = await this.actor.store_icrc1_canister(ledger, index_candid) - return candidToVault(vault) - } - - /** - * Method for removing from a personal list of ICRC-1 canisters by the user. - * Returns the updated vault state. - * Needed for displaying the balance/history of ICRC-1 tokens. - * @param ledger Ledger ICRC-1 canister to be removed. - * */ - async removeICRC1Canister(ledger: Principal): Promise { - const vault = await this.actor.remove_icrc1_canister(ledger) - return candidToVault(vault) - } - /** * Retrieves all user transactions. * In the foreseeable future, optional parameter will be used for filtering/pagination. diff --git a/packages/vaults/src/transaction/config/icrc1_add.ts b/packages/vaults/src/transaction/config/icrc1_add.ts new file mode 100644 index 00000000..585d83ed --- /dev/null +++ b/packages/vaults/src/transaction/config/icrc1_add.ts @@ -0,0 +1,79 @@ +import { TransactionType } from "../../enum/enums" +import { Transaction } from "../transaction" +import { + TransactionRequest as TransactionRequestCandid, + ICRC1CanistersAddTransaction as TransactionCandid, +} from "../../idl/service_vault" +import { TransactionMapperAbstract } from "../transaction_mapper" +import { TransactionRequest } from "../transaction_request" +import { RequestMapperAbstract } from "../request_mapper" +import {Principal} from "@dfinity/principal"; + +/** + * Transaction for adding ICRC1 canisters to vault. + * Can be requested/approved only by users with the admin role. + * This transaction can be executed in a batch, + * which means either all transactions marked with a single batch_id + * are executed or rejected together. + * This transaction requires onl 1 approval. + */ +export interface ICRC1CanistersAddTransaction extends Transaction { + /** + * The ledger canister id. + */ + ledger_canister: Principal + + /** + * The index canister id. Optional. + */ + index_canister?: Principal +} + +export class ICRC1CanistersAddTransactionRequest implements TransactionRequest { + ledger_canister: Principal + index_canister: Principal | undefined + batch_uid: string | undefined + + constructor(ledger_canister: Principal, index_canister?: Principal, batch_uid?: string) { + this.ledger_canister = ledger_canister + this.index_canister = index_canister + this.batch_uid = batch_uid + } + + getType(): string { + return "ICRC1CanistersAddTransactionRequest" + } +} + +export class ICRC1CanistersAddTransactionMapper extends TransactionMapperAbstract { + getVariant(): PropertyKey { + return "ICRC1CanistersAddTransactionV" + } + + convert(candid: TransactionCandid): ICRC1CanistersAddTransaction { + return { + ledger_canister: candid.ledger_canister, + index_canister: candid.index_canister.length === 0 ? undefined : candid.index_canister[0], + ...this.basicFieldsConvert(candid.common), + } + } + + getType(): TransactionType { + return TransactionType.ICRC1AddCanisters + } +} + +export class ICRC1CanistersAddTransactionRequestMapper extends RequestMapperAbstract { + toCandid(request: ICRC1CanistersAddTransactionRequest): TransactionRequestCandid { + return { + ICRC1CanistersAddTransactionRequestV: { + ledger_canister: request.ledger_canister, + index_canister: request.index_canister !== undefined ? [request.index_canister] : [], + batch_uid: request.batch_uid !== undefined ? [request.batch_uid] : [], + }, + } + } + getMappedRequestType(): string { + return "ICRC1CanistersAddTransactionRequest" + } +} diff --git a/packages/vaults/src/transaction/config/icrc1_remove.ts b/packages/vaults/src/transaction/config/icrc1_remove.ts new file mode 100644 index 00000000..f0d276ac --- /dev/null +++ b/packages/vaults/src/transaction/config/icrc1_remove.ts @@ -0,0 +1,70 @@ +import { TransactionType } from "../../enum/enums" +import { Transaction } from "../transaction" +import { + TransactionRequest as TransactionRequestCandid, + ICRC1CanistersAddTransaction as TransactionCandid, +} from "../../idl/service_vault" +import { TransactionMapperAbstract } from "../transaction_mapper" +import { TransactionRequest } from "../transaction_request" +import { RequestMapperAbstract } from "../request_mapper" +import {Principal} from "@dfinity/principal"; + +/** + * Transaction for removing ICRC1 canisters from vault. + * Can be requested/approved only by users with the admin role. + * This transaction can be executed in a batch, + * which means either all transactions marked with a single batch_id + * are executed or rejected together. + * This transaction requires onl 1 approval. + */ +export interface ICRC1CanistersRemoveTransaction extends Transaction { + /** + * The ledger canister id. + */ + ledger_canister: Principal +} + +export class ICRC1CanistersRemoveTransactionRequest implements TransactionRequest { + ledger_canister: Principal + batch_uid: string | undefined + + constructor(ledger_canister: Principal,batch_uid?: string) { + this.ledger_canister = ledger_canister + this.batch_uid = batch_uid + } + + getType(): string { + return "ICRC1CanistersRemoveTransactionRequest" + } +} + +export class ICRC1CanistersRemoveTransactionMapper extends TransactionMapperAbstract { + getVariant(): PropertyKey { + return "ICRC1CanistersRemoveTransactionV" + } + + convert(candid: TransactionCandid): ICRC1CanistersRemoveTransaction { + return { + ledger_canister: candid.ledger_canister, + ...this.basicFieldsConvert(candid.common), + } + } + + getType(): TransactionType { + return TransactionType.ICRC1RemoveCanisters + } +} + +export class ICRC1CanistersRemoveTransactionRequestMapper extends RequestMapperAbstract { + toCandid(request: ICRC1CanistersRemoveTransactionRequest): TransactionRequestCandid { + return { + ICRC1CanistersRemoveTransactionRequestV: { + ledger_canister: request.ledger_canister, + batch_uid: request.batch_uid !== undefined ? [request.batch_uid] : [], + }, + } + } + getMappedRequestType(): string { + return "ICRC1CanistersRemoveTransactionRequest" + } +} diff --git a/packages/vaults/src/transaction/config/index.ts b/packages/vaults/src/transaction/config/index.ts index 5467d736..dd2c81f4 100644 --- a/packages/vaults/src/transaction/config/index.ts +++ b/packages/vaults/src/transaction/config/index.ts @@ -3,6 +3,8 @@ export { ControllersUpdateTransactionRequest, } from "./controllers_update" export { type PurgeTransaction, PurgeTransactionRequest } from "./purge" +export { type ICRC1CanistersAddTransaction, ICRC1CanistersAddTransactionRequest } from "./icrc1_add" +export { type ICRC1CanistersRemoveTransaction, ICRC1CanistersRemoveTransactionRequest } from "./icrc1_remove" export { type QuorumUpdateTransaction, QuorumTransactionRequest } from "./quorum_update" export { type VaultUpdateNamingTransaction, VaultNamingTransactionRequest } from "./vault_naming" export { type VersionUpgradeTransaction, VersionUpgradeTransactionRequest } from "./version_upgrade" diff --git a/packages/vaults/src/transaction/mapper_registry.ts b/packages/vaults/src/transaction/mapper_registry.ts index 7cf406b2..252f4440 100644 --- a/packages/vaults/src/transaction/mapper_registry.ts +++ b/packages/vaults/src/transaction/mapper_registry.ts @@ -51,6 +51,11 @@ import { MemberExtendAccountTransactionMapper, MemberExtendICRC1AccountRequestMapper, } from "./member/member_extend_account" +import {ICRC1CanistersAddTransactionMapper, ICRC1CanistersAddTransactionRequestMapper} from "./config/icrc1_add"; +import { + ICRC1CanistersRemoveTransactionMapper, + ICRC1CanistersRemoveTransactionRequestMapper +} from "./config/icrc1_remove"; export const TransactionMapperRegistry: Map = new Map() export const RequestMapperRegistry: Map = new Map() @@ -90,6 +95,8 @@ export function registerTransactionMappers() { RegisterTransactionMapper(TransferQuorumTransactionMapper) RegisterTransactionMapper(ControllersUpdateTransactionMapper) RegisterTransactionMapper(TransferICRC1QuorumTransactionMapper) + RegisterTransactionMapper(ICRC1CanistersAddTransactionMapper) + RegisterTransactionMapper(ICRC1CanistersRemoveTransactionMapper) } export function registerRequestMappers() { @@ -114,4 +121,6 @@ export function registerRequestMappers() { RegisterRequestMapper(TopUpQuorumRequestMapper) RegisterRequestMapper(TransferQuorumRequestMapper) RegisterRequestMapper(TransferICRC1QuorumRequestMapper) + RegisterRequestMapper(ICRC1CanistersAddTransactionRequestMapper) + RegisterRequestMapper(ICRC1CanistersRemoveTransactionRequestMapper) } diff --git a/packages/vaults/src/vault_manager_i.ts b/packages/vaults/src/vault_manager_i.ts index 6d6f6cb3..48c2ed49 100644 --- a/packages/vaults/src/vault_manager_i.ts +++ b/packages/vaults/src/vault_manager_i.ts @@ -61,21 +61,4 @@ export interface VaultManagerI { * Retrieves the list of vault controllers. */ getControllers(): Promise> - - /** - * Method for adding a personal list of ICRC-1 canisters by the user. - * Returns the updated vault state. - * Needed for displaying the balance/history of ICRC-1 tokens. - * @param ledger Ledger ICRC-1 canister to be added. - * @param index Optional index ICRC-1 canister to be added. - */ - addICRC1Canister(ledger: Principal, index?: Principal): Promise - - /** - * Method for removing from a personal list of ICRC-1 canisters by the user. - * Returns the updated vault state. - * Needed for displaying the balance/history of ICRC-1 tokens. - * @param ledger Ledger ICRC-1 canister to be removed. - * */ - removeICRC1Canister(ledger: Principal): Promise }