diff --git a/canisters/icrc/errors.ts b/canisters/icrc/errors.ts deleted file mode 100644 index df818cd3ad..0000000000 --- a/canisters/icrc/errors.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { IDL } from '../../src/lib/stable'; - -export const BadFee = IDL.Record({ - expected_fee: IDL.Nat -}); -export type BadFee = { - expected_fee: bigint; -}; - -export const BadBurn = IDL.Record({ - min_burn_amount: IDL.Nat -}); -export type BadBurn = { - min_burn_amount: bigint; -}; - -export const InsufficientFunds = IDL.Record({ - balance: IDL.Nat -}); -export type InsufficientFunds = { - balance: bigint; -}; - -export const Duplicate = IDL.Record({ - duplicate_of: IDL.Nat -}); -export type Duplicate = { - duplicate_of: bigint; -}; - -export const GenericError = IDL.Record({ - error_code: IDL.Nat, - message: IDL.Text -}); -export type GenericError = { - error_code: bigint; - message: string; -}; diff --git a/canisters/icrc/icrc.did b/canisters/icrc/icrc.did deleted file mode 100644 index b64bd5ff4e..0000000000 --- a/canisters/icrc/icrc.did +++ /dev/null @@ -1,311 +0,0 @@ -// Combined from https://github.com/dfinity/ICRC-1/blob/main/standards/ICRC-1/ICRC-1.did -// and https://github.com/dfinity/ICRC-1/blob/main/standards/ICRC-2/ICRC-2.did - -// Number of nanoseconds since the UNIX epoch in UTC timezone. -type Timestamp = nat64; - -// Number of nanoseconds between two [Timestamp]s. -type Duration = nat64; - -type Subaccount = blob; - -type Account = record { - owner : principal; - subaccount : opt Subaccount; -}; - -type TransferArgs = record { - from_subaccount : opt Subaccount; - to : Account; - amount : nat; - fee : opt nat; - memo : opt blob; - created_at_time : opt Timestamp; -}; - -type TransferError = variant { - BadFee : record { expected_fee : nat }; - BadBurn : record { min_burn_amount : nat }; - InsufficientFunds : record { balance : nat }; - TooOld; - CreatedInFuture: record { ledger_time : Timestamp }; - Duplicate : record { duplicate_of : nat }; - TemporarilyUnavailable; - GenericError : record { error_code : nat; message : text }; -}; - -type Value = variant { - Nat : nat; - Int : int; - Text : text; - Blob : blob; -}; - -type ApproveArgs = record { - from_subaccount : opt blob; - spender : Account; - amount : nat; - expected_allowance : opt nat; - expires_at : opt nat64; - fee : opt nat; - memo : opt blob; - created_at_time : opt nat64; -}; - -type ApproveError = variant { - BadFee : record { expected_fee : nat }; - InsufficientFunds : record { balance : nat }; - AllowanceChanged : record { current_allowance : nat }; - Expired : record { ledger_time : nat64 }; - TooOld; - CreatedInFuture: record { ledger_time : nat64 }; - Duplicate : record { duplicate_of : nat }; - TemporarilyUnavailable; - GenericError : record { error_code : nat; message : text }; -}; - -type TransferFromArgs = record { - spender_subaccount : opt blob; - from : Account; - to : Account; - amount : nat; - fee : opt nat; - memo : opt blob; - created_at_time : opt nat64; -}; - -type TransferFromError = variant { - BadFee : record { expected_fee : nat }; - BadBurn : record { min_burn_amount : nat }; - InsufficientFunds : record { balance : nat }; - InsufficientAllowance : record { allowance : nat }; - TooOld; - CreatedInFuture: record { ledger_time : nat64 }; - Duplicate : record { duplicate_of : nat }; - TemporarilyUnavailable; - GenericError : record { error_code : nat; message : text }; -}; - -type AllowanceArgs = record { - account : Account; - spender : Account; -}; - -service : { - icrc1_metadata : () -> (vec record { text; Value; }) query; - icrc1_name : () -> (text) query; - icrc1_symbol : () -> (text) query; - icrc1_decimals : () -> (nat8) query; - icrc1_fee : () -> (nat) query; - icrc1_total_supply : () -> (nat) query; - icrc1_minting_account : () -> (opt Account) query; - icrc1_balance_of : (Account) -> (nat) query; - icrc1_transfer : (TransferArgs) -> (variant { Ok : nat; Err : TransferError }); - icrc1_supported_standards : () -> (vec record { name : text; url : text }) query; - - icrc2_approve : (ApproveArgs) -> (variant { Ok : nat; Err : ApproveError }); - icrc2_transfer_from : (TransferFromArgs) -> (variant { Ok : nat; Err : TransferFromError }); - icrc2_allowance : (AllowanceArgs) -> (record { allowance : nat; expires_at : opt nat64 }) query; -} - -// Apache License -// Version 2.0, January 2004 -// http://www.apache.org/licenses/ - -// TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -// 1. Definitions. - -// "License" shall mean the terms and conditions for use, reproduction, -// and distribution as defined by Sections 1 through 9 of this document. - -// "Licensor" shall mean the copyright owner or entity authorized by -// the copyright owner that is granting the License. - -// "Legal Entity" shall mean the union of the acting entity and all -// other entities that control, are controlled by, or are under common -// control with that entity. For the purposes of this definition, -// "control" means (i) the power, direct or indirect, to cause the -// direction or management of such entity, whether by contract or -// otherwise, or (ii) ownership of fifty percent (50%) or more of the -// outstanding shares, or (iii) beneficial ownership of such entity. - -// "You" (or "Your") shall mean an individual or Legal Entity -// exercising permissions granted by this License. - -// "Source" form shall mean the preferred form for making modifications, -// including but not limited to software source code, documentation -// source, and configuration files. - -// "Object" form shall mean any form resulting from mechanical -// transformation or translation of a Source form, including but -// not limited to compiled object code, generated documentation, -// and conversions to other media types. - -// "Work" shall mean the work of authorship, whether in Source or -// Object form, made available under the License, as indicated by a -// copyright notice that is included in or attached to the work -// (an example is provided in the Appendix below). - -// "Derivative Works" shall mean any work, whether in Source or Object -// form, that is based on (or derived from) the Work and for which the -// editorial revisions, annotations, elaborations, or other modifications -// represent, as a whole, an original work of authorship. For the purposes -// of this License, Derivative Works shall not include works that remain -// separable from, or merely link (or bind by name) to the interfaces of, -// the Work and Derivative Works thereof. - -// "Contribution" shall mean any work of authorship, including -// the original version of the Work and any modifications or additions -// to that Work or Derivative Works thereof, that is intentionally -// submitted to Licensor for inclusion in the Work by the copyright owner -// or by an individual or Legal Entity authorized to submit on behalf of -// the copyright owner. For the purposes of this definition, "submitted" -// means any form of electronic, verbal, or written communication sent -// to the Licensor or its representatives, including but not limited to -// communication on electronic mailing lists, source code control systems, -// and issue tracking systems that are managed by, or on behalf of, the -// Licensor for the purpose of discussing and improving the Work, but -// excluding communication that is conspicuously marked or otherwise -// designated in writing by the copyright owner as "Not a Contribution." - -// "Contributor" shall mean Licensor and any individual or Legal Entity -// on behalf of whom a Contribution has been received by Licensor and -// subsequently incorporated within the Work. - -// 2. Grant of Copyright License. Subject to the terms and conditions of -// this License, each Contributor hereby grants to You a perpetual, -// worldwide, non-exclusive, no-charge, royalty-free, irrevocable -// copyright license to reproduce, prepare Derivative Works of, -// publicly display, publicly perform, sublicense, and distribute the -// Work and such Derivative Works in Source or Object form. - -// 3. Grant of Patent License. Subject to the terms and conditions of -// this License, each Contributor hereby grants to You a perpetual, -// worldwide, non-exclusive, no-charge, royalty-free, irrevocable -// (except as stated in this section) patent license to make, have made, -// use, offer to sell, sell, import, and otherwise transfer the Work, -// where such license applies only to those patent claims licensable -// by such Contributor that are necessarily infringed by their -// Contribution(s) alone or by combination of their Contribution(s) -// with the Work to which such Contribution(s) was submitted. If You -// institute patent litigation against any entity (including a -// cross-claim or counterclaim in a lawsuit) alleging that the Work -// or a Contribution incorporated within the Work constitutes direct -// or contributory patent infringement, then any patent licenses -// granted to You under this License for that Work shall terminate -// as of the date such litigation is filed. - -// 4. Redistribution. You may reproduce and distribute copies of the -// Work or Derivative Works thereof in any medium, with or without -// modifications, and in Source or Object form, provided that You -// meet the following conditions: - -// (a) You must give any other recipients of the Work or -// Derivative Works a copy of this License; and - -// (b) You must cause any modified files to carry prominent notices -// stating that You changed the files; and - -// (c) You must retain, in the Source form of any Derivative Works -// that You distribute, all copyright, patent, trademark, and -// attribution notices from the Source form of the Work, -// excluding those notices that do not pertain to any part of -// the Derivative Works; and - -// (d) If the Work includes a "NOTICE" text file as part of its -// distribution, then any Derivative Works that You distribute must -// include a readable copy of the attribution notices contained -// within such NOTICE file, excluding those notices that do not -// pertain to any part of the Derivative Works, in at least one -// of the following places: within a NOTICE text file distributed -// as part of the Derivative Works; within the Source form or -// documentation, if provided along with the Derivative Works; or, -// within a display generated by the Derivative Works, if and -// wherever such third-party notices normally appear. The contents -// of the NOTICE file are for informational purposes only and -// do not modify the License. You may add Your own attribution -// notices within Derivative Works that You distribute, alongside -// or as an addendum to the NOTICE text from the Work, provided -// that such additional attribution notices cannot be construed -// as modifying the License. - -// You may add Your own copyright statement to Your modifications and -// may provide additional or different license terms and conditions -// for use, reproduction, or distribution of Your modifications, or -// for any such Derivative Works as a whole, provided Your use, -// reproduction, and distribution of the Work otherwise complies with -// the conditions stated in this License. - -// 5. Submission of Contributions. Unless You explicitly state otherwise, -// any Contribution intentionally submitted for inclusion in the Work -// by You to the Licensor shall be under the terms and conditions of -// this License, without any additional terms or conditions. -// Notwithstanding the above, nothing herein shall supersede or modify -// the terms of any separate license agreement you may have executed -// with Licensor regarding such Contributions. - -// 6. Trademarks. This License does not grant permission to use the trade -// names, trademarks, service marks, or product names of the Licensor, -// except as required for reasonable and customary use in describing the -// origin of the Work and reproducing the content of the NOTICE file. - -// 7. Disclaimer of Warranty. Unless required by applicable law or -// agreed to in writing, Licensor provides the Work (and each -// Contributor provides its Contributions) on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied, including, without limitation, any warranties or conditions -// of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A -// PARTICULAR PURPOSE. You are solely responsible for determining the -// appropriateness of using or redistributing the Work and assume any -// risks associated with Your exercise of permissions under this License. - -// 8. Limitation of Liability. In no event and under no legal theory, -// whether in tort (including negligence), contract, or otherwise, -// unless required by applicable law (such as deliberate and grossly -// negligent acts) or agreed to in writing, shall any Contributor be -// liable to You for damages, including any direct, indirect, special, -// incidental, or consequential damages of any character arising as a -// result of this License or out of the use or inability to use the -// Work (including but not limited to damages for loss of goodwill, -// work stoppage, computer failure or malfunction, or any and all -// other commercial damages or losses), even if such Contributor -// has been advised of the possibility of such damages. - -// 9. Accepting Warranty or Additional Liability. While redistributing -// the Work or Derivative Works thereof, You may choose to offer, -// and charge a fee for, acceptance of support, warranty, indemnity, -// or other liability obligations and/or rights consistent with this -// License. However, in accepting such obligations, You may act only -// on Your own behalf and on Your sole responsibility, not on behalf -// of any other Contributor, and only if You agree to indemnify, -// defend, and hold each Contributor harmless for any liability -// incurred by, or claims asserted against, such Contributor by reason -// of your accepting any such warranty or additional liability. - -// END OF TERMS AND CONDITIONS - -// APPENDIX: How to apply the Apache License to your work. - -// To apply the Apache License to your work, attach the following -// boilerplate notice, with the fields enclosed by brackets "[]" -// replaced with your own identifying information. (Don't include -// the brackets!) The text should be enclosed in the appropriate -// comment syntax for the file format. We also recommend that a -// file or class name and description of purpose be included on the -// same "printed page" as the copyright notice for easier -// identification within third-party archives. - -// Copyright 2023 DFINITY Foundation - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. diff --git a/canisters/icrc/icrc_1.ts b/canisters/icrc/icrc_1.ts deleted file mode 100644 index c5886e6adf..0000000000 --- a/canisters/icrc/icrc_1.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { IDL, Principal } from '../../src/lib/stable'; -import { - BadBurn, - BadFee, - Duplicate, - GenericError, - InsufficientFunds -} from './errors'; - -// Number of nanoseconds since the UNIX epoch in UTC timezone. -export const Timestamp = IDL.Nat64; -export type Timestamp = bigint; - -export const Subaccount = IDL.Vec(IDL.Nat8); -export type Subaccount = Uint8Array; - -export const Account = IDL.Record({ - owner: IDL.Principal, - subaccount: IDL.Opt(Subaccount) -}); -export type Account = { - owner: Principal; - subaccount: [Subaccount] | []; -}; - -export const TransferArgs = IDL.Record({ - from_subaccount: IDL.Opt(Subaccount), - to: Account, - amount: IDL.Nat, - fee: IDL.Opt(IDL.Nat), - memo: IDL.Opt(IDL.Vec(IDL.Nat8)), - created_at_time: IDL.Opt(Timestamp) -}); -export type TransferArgs = { - from_subaccount: [Subaccount] | []; - to: Account; - amount: bigint; - fee: [bigint] | []; - memo: [Uint8Array] | []; - created_at_time: [Timestamp] | []; -}; - -export const CreatedInFuture = IDL.Record({ - ledger_time: Timestamp -}); -export type CreatedInFuture = { - ledger_time: Timestamp; -}; - -export const TransferError = IDL.Variant({ - BadFee, - BadBurn, - InsufficientFunds, - TooOld: IDL.Null, - CreatedInFuture: CreatedInFuture, - Duplicate: Duplicate, - TemporarilyUnavailable: IDL.Null, - GenericError: GenericError -}); -export type TransferError = - | { - BadFee: BadFee; - } - | { - BadBurn: BadBurn; - } - | { - InsufficientFunds: InsufficientFunds; - } - | { - TooOld: null; - } - | { - CreatedInFuture: CreatedInFuture; - } - | { - Duplicate: Duplicate; - } - | { - TemporarilyUnavailable: null; - } - | { - GenericError: GenericError; - }; - -export const TransferResult = IDL.Variant({ - Ok: IDL.Nat, - Err: TransferError -}); -export type TransferResult = { Ok: bigint } | { Err: TransferError }; - -export const Value = IDL.Variant({ - Nat: IDL.Nat, - Int: IDL.Int, - Text: IDL.Text, - Blob: IDL.Vec(IDL.Nat8) -}); -export type Value = - | { - Nat: bigint; - } - | { - Int: bigint; - } - | { - Text: string; - } - | { - Blob: Uint8Array; - }; diff --git a/canisters/icrc/icrc_2.ts b/canisters/icrc/icrc_2.ts deleted file mode 100644 index 18324d4d81..0000000000 --- a/canisters/icrc/icrc_2.ts +++ /dev/null @@ -1,192 +0,0 @@ -import { IDL } from '../../src/lib/stable'; -import { - BadBurn, - BadFee, - Duplicate, - GenericError, - InsufficientFunds -} from './errors'; -import { Account, CreatedInFuture } from './icrc_1'; - -export const ApproveArgs = IDL.Record({ - from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), - spender: Account, - amount: IDL.Nat, - expected_allowance: IDL.Opt(IDL.Nat), - expires_at: IDL.Opt(IDL.Nat64), - fee: IDL.Opt(IDL.Nat), - memo: IDL.Opt(IDL.Vec(IDL.Nat8)), - created_at_time: IDL.Opt(IDL.Nat64) -}); -export type ApproveArgs = { - from_subaccount: [Uint8Array] | []; - spender: Account; - amount: bigint; - expected_allowance: [bigint] | []; - expires_at: [bigint] | []; - fee: [bigint] | []; - memo: [Uint8Array] | []; - created_at_time: [bigint] | []; -}; - -export const AllowanceChanged = IDL.Record({ - current_allowance: IDL.Nat -}); -export type AllowanceChanged = { - current_allowance: bigint; -}; - -export const Expired = IDL.Record({ - ledger_time: IDL.Nat64 -}); -export type Expired = { - ledger_time: bigint; -}; - -export const InsufficientAllowance = IDL.Record({ - allowance: IDL.Nat -}); -export type InsufficientAllowance = { - allowance: bigint; -}; - -export const ApproveError = IDL.Variant({ - BadFee, - InsufficientFunds, - AllowanceChanged, - Expired, - TooOld: IDL.Null, - CreatedInFuture, - Duplicate, - TemporarilyUnavailable: IDL.Null, - GenericError: GenericError -}); -export type ApproveError = - | { - BadFee: BadFee; - } - | { - InsufficientFunds: InsufficientFunds; - } - | { - AllowanceChanged: AllowanceChanged; - } - | { - Expired: Expired; - } - | { - TooOld: null; - } - | { - CreatedInFuture: CreatedInFuture; - } - | { - Duplicate: Duplicate; - } - | { - TemporarilyUnavailable: null; - } - | { - GenericError: GenericError; - }; - -export const TransferFromArgs = IDL.Record({ - spender_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), - from: Account, - to: Account, - amount: IDL.Nat, - fee: IDL.Opt(IDL.Nat), - memo: IDL.Opt(IDL.Vec(IDL.Nat8)), - created_at_time: IDL.Opt(IDL.Nat64) -}); -export type TransferFromArgs = { - spender_subaccount: [Uint8Array] | []; - from: Account; - to: Account; - amount: bigint; - fee: [bigint] | []; - memo: [Uint8Array] | []; - created_at_time: [bigint] | []; -}; - -export const TransferFromError = IDL.Variant({ - BadFee, - BadBurn, - InsufficientFunds, - InsufficientAllowance, - TooOld: IDL.Null, - CreatedInFuture, - Duplicate, - TemporarilyUnavailable: IDL.Null, - GenericError -}); -export type TransferFromError = - | { - BadFee: BadFee; - } - | { - BadBurn: BadBurn; - } - | { - InsufficientFunds: InsufficientFunds; - } - | { - InsufficientAllowance: InsufficientAllowance; - } - | { - TooOld: null; - } - | { - CreatedInFuture: CreatedInFuture; - } - | { - Duplicate: Duplicate; - } - | { - TemporarilyUnavailable: null; - } - | { - GenericError: GenericError; - }; - -export const AllowanceArgs = IDL.Record({ - account: Account, - spender: Account -}); -export type AllowanceArgs = { - account: Account; - spender: Account; -}; - -export const ApproveResult = IDL.Variant({ - Ok: IDL.Nat, - Err: ApproveError -}); -export type ApproveResult = - | { - Ok: bigint; - } - | { - Err: ApproveError; - }; - -export const TransferFromResult = IDL.Variant({ - Ok: IDL.Nat, - Err: TransferFromError -}); -export type TransferFromResult = - | { - Ok: bigint; - } - | { - Err: TransferFromError; - }; - -export const AllowanceResult = IDL.Record({ - allowance: IDL.Nat, - expires_at: IDL.Opt(IDL.Nat64) -}); -export type AllowanceResult = { - allowance: bigint; - expires_at: [bigint] | []; -}; diff --git a/canisters/icrc/index.ts b/canisters/icrc/index.ts deleted file mode 100644 index 0ad69523ef..0000000000 --- a/canisters/icrc/index.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { IDL } from '../../src/lib/stable'; -import { Account, TransferArgs, TransferResult, Value } from './icrc_1'; -import { - AllowanceArgs, - AllowanceResult, - ApproveArgs, - ApproveResult, - TransferFromArgs, - TransferFromResult -} from './icrc_2'; - -export const SupportedStandard = IDL.Record({ - name: IDL.Text, - url: IDL.Text -}); -export type SupportedStandard = { - name: string; - url: string; -}; - -export const ICRC = IDL.Service({ - icrc1_metadata: IDL.Func( - [], - [IDL.Vec(IDL.Tuple(IDL.Text, Value))], - ['query'] - ), - icrc1_name: IDL.Func([], [IDL.Text], ['query']), - icrc1_symbol: IDL.Func([], [IDL.Text], ['query']), - icrc1_decimals: IDL.Func([], [IDL.Nat8], ['query']), - icrc1_fee: IDL.Func([], [IDL.Nat], ['query']), - icrc1_total_supply: IDL.Func([], [IDL.Nat], ['query']), - icrc1_minting_account: IDL.Func([], [IDL.Opt(Account)], ['query']), - icrc1_balance_of: IDL.Func([Account], [IDL.Nat], ['query']), - icrc1_transfer: IDL.Func([TransferArgs], [TransferResult]), - icrc1_supported_standards: IDL.Func( - [], - [IDL.Vec(SupportedStandard)], - ['query'] - ), - icrc2_approve: IDL.Func([ApproveArgs], [ApproveResult]), - icrc2_transfer_from: IDL.Func([TransferFromArgs], [TransferFromResult]), - icrc2_allowance: IDL.Func([AllowanceArgs], [AllowanceResult], ['query']) -}); - -export * from './icrc_1'; -export * from './icrc_2'; diff --git a/canisters/icrc_1/ICRC-1.did b/canisters/icrc_1/ICRC-1.did new file mode 100644 index 0000000000..989028bb8e --- /dev/null +++ b/canisters/icrc_1/ICRC-1.did @@ -0,0 +1,63 @@ +// Taken from: https://github.com/dfinity/ICRC-1/blob/effeeaa89d8dd75ce3b2215b9c36eed98dafb7a8/standards/ICRC-1/ICRC-1.did + +// Number of nanoseconds since the UNIX epoch in UTC timezone. +type Timestamp = nat64; + +// Number of nanoseconds between two [Timestamp]s. +type Duration = nat64; + +type Subaccount = blob; + +type Account = record { + owner : principal; + subaccount : opt Subaccount; +}; + +type TransferArgs = record { + from_subaccount : opt Subaccount; + to : Account; + amount : nat; + fee : opt nat; + memo : opt blob; + created_at_time : opt Timestamp; +}; + +// TODO added by Demergent Labs, would be nice to upstream or automate +type TransferResult = variant { Ok : nat; Err : TransferError }; + +type TransferError = variant { + BadFee : record { expected_fee : nat }; + BadBurn : record { min_burn_amount : nat }; + InsufficientFunds : record { balance : nat }; + TooOld; + CreatedInFuture: record { ledger_time : Timestamp }; + Duplicate : record { duplicate_of : nat }; + TemporarilyUnavailable; + GenericError : record { error_code : nat; message : text }; +}; + +type Value = variant { + Nat : nat; + Int : int; + Text : text; + Blob : blob; +}; + +// TODO added by Demergent Labs, would be nice to upstream or automate +type Metadatum = record { text; Value; }; + +// TODO added by Demergent Labs, would be nice to upstream or automate +type SupportedStandard = record { name : text; url : text }; + +service : { + icrc1_metadata : () -> (vec Metadatum) query; + icrc1_name : () -> (text) query; + icrc1_symbol : () -> (text) query; + icrc1_decimals : () -> (nat8) query; + icrc1_fee : () -> (nat) query; + icrc1_total_supply : () -> (nat) query; + icrc1_minting_account : () -> (opt Account) query; + icrc1_balance_of : (Account) -> (nat) query; + icrc1_transfer : (TransferArgs) -> (TransferResult); + icrc1_supported_standards : () -> (vec SupportedStandard) query; +} diff --git a/canisters/icrc/LICENSE b/canisters/icrc_1/LICENSE similarity index 100% rename from canisters/icrc/LICENSE rename to canisters/icrc_1/LICENSE diff --git a/canisters/icrc_1/index.ts b/canisters/icrc_1/index.ts new file mode 100644 index 0000000000..7755df0237 --- /dev/null +++ b/canisters/icrc_1/index.ts @@ -0,0 +1,150 @@ +import { ActorMethod } from '@dfinity/agent'; +import { IDL } from '@dfinity/candid'; +import { Principal } from '@dfinity/principal'; +export interface Account { + owner: Principal; + subaccount: [] | [Subaccount]; +} +export type Duration = bigint; +export type Metadatum = [string, Value]; +export type Subaccount = Uint8Array | number[]; +export interface SupportedStandard { + url: string; + name: string; +} +export type Timestamp = bigint; +export interface TransferArgs { + to: Account; + fee: [] | [bigint]; + memo: [] | [Uint8Array | number[]]; + from_subaccount: [] | [Subaccount]; + created_at_time: [] | [Timestamp]; + amount: bigint; +} +export type TransferError = + | { + GenericError: { message: string; error_code: bigint }; + } + | { TemporarilyUnavailable: null } + | { BadBurn: { min_burn_amount: bigint } } + | { Duplicate: { duplicate_of: bigint } } + | { BadFee: { expected_fee: bigint } } + | { CreatedInFuture: { ledger_time: Timestamp } } + | { TooOld: null } + | { InsufficientFunds: { balance: bigint } }; +export type TransferResult = { Ok: bigint } | { Err: TransferError }; +export type Value = + | { Int: bigint } + | { Nat: bigint } + | { Blob: Uint8Array | number[] } + | { Text: string }; +export interface _SERVICE { + icrc1_balance_of: ActorMethod<[Account], bigint>; + icrc1_decimals: ActorMethod<[], number>; + icrc1_fee: ActorMethod<[], bigint>; + icrc1_metadata: ActorMethod<[], Array>; + icrc1_minting_account: ActorMethod<[], [] | [Account]>; + icrc1_name: ActorMethod<[], string>; + icrc1_supported_standards: ActorMethod<[], Array>; + icrc1_symbol: ActorMethod<[], string>; + icrc1_total_supply: ActorMethod<[], bigint>; + icrc1_transfer: ActorMethod<[TransferArgs], TransferResult>; +} +export type idlFactory = IDL.InterfaceFactory; +export type init = (args: { IDL: typeof IDL }) => IDL.Type[]; +export const Subaccount = IDL.Vec(IDL.Nat8); +export const Account = IDL.Record({ + owner: IDL.Principal, + subaccount: IDL.Opt(Subaccount) +}); +export const Value = IDL.Variant({ + Int: IDL.Int, + Nat: IDL.Nat, + Blob: IDL.Vec(IDL.Nat8), + Text: IDL.Text +}); +export const Metadatum = IDL.Tuple(IDL.Text, Value); +export const SupportedStandard = IDL.Record({ + url: IDL.Text, + name: IDL.Text +}); +export const Timestamp = IDL.Nat64; +export const TransferArgs = IDL.Record({ + to: Account, + fee: IDL.Opt(IDL.Nat), + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + from_subaccount: IDL.Opt(Subaccount), + created_at_time: IDL.Opt(Timestamp), + amount: IDL.Nat +}); +export const TransferError = IDL.Variant({ + GenericError: IDL.Record({ message: IDL.Text, error_code: IDL.Nat }), + TemporarilyUnavailable: IDL.Null, + BadBurn: IDL.Record({ min_burn_amount: IDL.Nat }), + Duplicate: IDL.Record({ duplicate_of: IDL.Nat }), + BadFee: IDL.Record({ expected_fee: IDL.Nat }), + CreatedInFuture: IDL.Record({ ledger_time: Timestamp }), + TooOld: IDL.Null, + InsufficientFunds: IDL.Record({ balance: IDL.Nat }) +}); +export const TransferResult = IDL.Variant({ + Ok: IDL.Nat, + Err: TransferError +}); +export const idlFactory: idlFactory = ({ IDL }) => { + const Subaccount = IDL.Vec(IDL.Nat8); + const Account = IDL.Record({ + owner: IDL.Principal, + subaccount: IDL.Opt(Subaccount) + }); + const Value = IDL.Variant({ + Int: IDL.Int, + Nat: IDL.Nat, + Blob: IDL.Vec(IDL.Nat8), + Text: IDL.Text + }); + const Metadatum = IDL.Tuple(IDL.Text, Value); + const SupportedStandard = IDL.Record({ url: IDL.Text, name: IDL.Text }); + const Timestamp = IDL.Nat64; + const TransferArgs = IDL.Record({ + to: Account, + fee: IDL.Opt(IDL.Nat), + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + from_subaccount: IDL.Opt(Subaccount), + created_at_time: IDL.Opt(Timestamp), + amount: IDL.Nat + }); + const TransferError = IDL.Variant({ + GenericError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TemporarilyUnavailable: IDL.Null, + BadBurn: IDL.Record({ min_burn_amount: IDL.Nat }), + Duplicate: IDL.Record({ duplicate_of: IDL.Nat }), + BadFee: IDL.Record({ expected_fee: IDL.Nat }), + CreatedInFuture: IDL.Record({ ledger_time: Timestamp }), + TooOld: IDL.Null, + InsufficientFunds: IDL.Record({ balance: IDL.Nat }) + }); + const TransferResult = IDL.Variant({ Ok: IDL.Nat, Err: TransferError }); + return IDL.Service({ + icrc1_balance_of: IDL.Func([Account], [IDL.Nat], ['query']), + icrc1_decimals: IDL.Func([], [IDL.Nat8], ['query']), + icrc1_fee: IDL.Func([], [IDL.Nat], ['query']), + icrc1_metadata: IDL.Func([], [IDL.Vec(Metadatum)], ['query']), + icrc1_minting_account: IDL.Func([], [IDL.Opt(Account)], ['query']), + icrc1_name: IDL.Func([], [IDL.Text], ['query']), + icrc1_supported_standards: IDL.Func( + [], + [IDL.Vec(SupportedStandard)], + ['query'] + ), + icrc1_symbol: IDL.Func([], [IDL.Text], ['query']), + icrc1_total_supply: IDL.Func([], [IDL.Nat], ['query']), + icrc1_transfer: IDL.Func([TransferArgs], [TransferResult], []) + }); +}; +export const init: init = () => { + return []; +}; diff --git a/canisters/icrc_10/ICRC-10.did b/canisters/icrc_10/ICRC-10.did new file mode 100644 index 0000000000..d9a1c6a7c2 --- /dev/null +++ b/canisters/icrc_10/ICRC-10.did @@ -0,0 +1,8 @@ +// Taken from: https://github.com/dfinity/ICRC/blob/946bd6518acb2aafd1828b93dfde9e47657fd758/ICRCs/ICRC-10/ICRC-10.did + +type SupportedStandard = record { name : text; url : text; }; +type SupportedStandardsResponse = vec SupportedStandard; + +service : { + icrc10_supported_standards : () -> (SupportedStandardsResponse) query; +} diff --git a/canisters/icrc_10/LICENSE b/canisters/icrc_10/LICENSE new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/canisters/icrc_10/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/canisters/icrc_10/index.ts b/canisters/icrc_10/index.ts new file mode 100644 index 0000000000..16496d6777 --- /dev/null +++ b/canisters/icrc_10/index.ts @@ -0,0 +1,31 @@ +import { ActorMethod } from '@dfinity/agent'; +import { IDL } from '@dfinity/candid'; +export interface SupportedStandard { + url: string; + name: string; +} +export type SupportedStandardsResponse = Array; +export interface _SERVICE { + icrc10_supported_standards: ActorMethod<[], SupportedStandardsResponse>; +} +export type idlFactory = IDL.InterfaceFactory; +export type init = (args: { IDL: typeof IDL }) => IDL.Type[]; +export const SupportedStandard = IDL.Record({ + url: IDL.Text, + name: IDL.Text +}); +export const SupportedStandardsResponse = IDL.Vec(SupportedStandard); +export const idlFactory: idlFactory = ({ IDL }) => { + const SupportedStandard = IDL.Record({ url: IDL.Text, name: IDL.Text }); + const SupportedStandardsResponse = IDL.Vec(SupportedStandard); + return IDL.Service({ + icrc10_supported_standards: IDL.Func( + [], + [SupportedStandardsResponse], + ['query'] + ) + }); +}; +export const init: init = () => { + return []; +}; diff --git a/canisters/icrc_2/ICRC-2.did b/canisters/icrc_2/ICRC-2.did new file mode 100644 index 0000000000..8aae190f5e --- /dev/null +++ b/canisters/icrc_2/ICRC-2.did @@ -0,0 +1,76 @@ +// Taken from: https://github.com/dfinity/ICRC-1/blob/effeeaa89d8dd75ce3b2215b9c36eed98dafb7a8/standards/ICRC-2/ICRC-2.did + +type Account = record { + owner : principal; + subaccount : opt blob; +}; + +type ApproveArgs = record { + from_subaccount : opt blob; + spender : Account; + amount : nat; + expected_allowance : opt nat; + expires_at : opt nat64; + fee : opt nat; + memo : opt blob; + created_at_time : opt nat64; +}; + +// TODO added by Demergent Labs, would be nice to upstream or automate +type ApproveResult = variant { Ok : nat; Err : ApproveError }; + +type ApproveError = variant { + BadFee : record { expected_fee : nat }; + InsufficientFunds : record { balance : nat }; + AllowanceChanged : record { current_allowance : nat }; + Expired : record { ledger_time : nat64 }; + TooOld; + CreatedInFuture: record { ledger_time : nat64 }; + Duplicate : record { duplicate_of : nat }; + TemporarilyUnavailable; + GenericError : record { error_code : nat; message : text }; +}; + +type TransferFromArgs = record { + spender_subaccount : opt blob; + from : Account; + to : Account; + amount : nat; + fee : opt nat; + memo : opt blob; + created_at_time : opt nat64; +}; + +// TODO added by Demergent Labs, would be nice to upstream or automate +type TransferFromResult = variant { Ok : nat; Err : TransferFromError }; + +type TransferFromError = variant { + BadFee : record { expected_fee : nat }; + BadBurn : record { min_burn_amount : nat }; + InsufficientFunds : record { balance : nat }; + InsufficientAllowance : record { allowance : nat }; + TooOld; + CreatedInFuture: record { ledger_time : nat64 }; + Duplicate : record { duplicate_of : nat }; + TemporarilyUnavailable; + GenericError : record { error_code : nat; message : text }; +}; + +type AllowanceArgs = record { + account : Account; + spender : Account; +}; + +// TODO added by Demergent Labs, would be nice to upstream or automate +type AllowanceResult = record { allowance : nat; expires_at : opt nat64 }; + +// TODO added by Demergent Labs, would be nice to upstream or automate +type SupportedStandard = record { name : text; url : text }; + +service : { + icrc1_supported_standards : () -> (vec SupportedStandard) query; + + icrc2_approve : (ApproveArgs) -> (ApproveResult); + icrc2_transfer_from : (TransferFromArgs) -> (TransferFromResult); + icrc2_allowance : (AllowanceArgs) -> (AllowanceResult) query; +} diff --git a/canisters/icrc_2/LICENSE b/canisters/icrc_2/LICENSE new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/canisters/icrc_2/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/canisters/icrc_2/index.ts b/canisters/icrc_2/index.ts new file mode 100644 index 0000000000..6ad93ad0c2 --- /dev/null +++ b/canisters/icrc_2/index.ts @@ -0,0 +1,225 @@ +import { ActorMethod } from '@dfinity/agent'; +import { IDL } from '@dfinity/candid'; +import { Principal } from '@dfinity/principal'; +export interface Account { + owner: Principal; + subaccount: [] | [Uint8Array | number[]]; +} +export interface AllowanceArgs { + account: Account; + spender: Account; +} +export interface AllowanceResult { + allowance: bigint; + expires_at: [] | [bigint]; +} +export interface ApproveArgs { + fee: [] | [bigint]; + memo: [] | [Uint8Array | number[]]; + from_subaccount: [] | [Uint8Array | number[]]; + created_at_time: [] | [bigint]; + amount: bigint; + expected_allowance: [] | [bigint]; + expires_at: [] | [bigint]; + spender: Account; +} +export type ApproveError = + | { + GenericError: { message: string; error_code: bigint }; + } + | { TemporarilyUnavailable: null } + | { Duplicate: { duplicate_of: bigint } } + | { BadFee: { expected_fee: bigint } } + | { AllowanceChanged: { current_allowance: bigint } } + | { CreatedInFuture: { ledger_time: bigint } } + | { TooOld: null } + | { Expired: { ledger_time: bigint } } + | { InsufficientFunds: { balance: bigint } }; +export type ApproveResult = { Ok: bigint } | { Err: ApproveError }; +export interface SupportedStandard { + url: string; + name: string; +} +export interface TransferFromArgs { + to: Account; + fee: [] | [bigint]; + spender_subaccount: [] | [Uint8Array | number[]]; + from: Account; + memo: [] | [Uint8Array | number[]]; + created_at_time: [] | [bigint]; + amount: bigint; +} +export type TransferFromError = + | { + GenericError: { message: string; error_code: bigint }; + } + | { TemporarilyUnavailable: null } + | { InsufficientAllowance: { allowance: bigint } } + | { BadBurn: { min_burn_amount: bigint } } + | { Duplicate: { duplicate_of: bigint } } + | { BadFee: { expected_fee: bigint } } + | { CreatedInFuture: { ledger_time: bigint } } + | { TooOld: null } + | { InsufficientFunds: { balance: bigint } }; +export type TransferFromResult = { Ok: bigint } | { Err: TransferFromError }; +export interface _SERVICE { + icrc1_supported_standards: ActorMethod<[], Array>; + icrc2_allowance: ActorMethod<[AllowanceArgs], AllowanceResult>; + icrc2_approve: ActorMethod<[ApproveArgs], ApproveResult>; + icrc2_transfer_from: ActorMethod<[TransferFromArgs], TransferFromResult>; +} +export type idlFactory = IDL.InterfaceFactory; +export type init = (args: { IDL: typeof IDL }) => IDL.Type[]; +export const SupportedStandard = IDL.Record({ + url: IDL.Text, + name: IDL.Text +}); +export const Account = IDL.Record({ + owner: IDL.Principal, + subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)) +}); +export const AllowanceArgs = IDL.Record({ + account: Account, + spender: Account +}); +export const AllowanceResult = IDL.Record({ + allowance: IDL.Nat, + expires_at: IDL.Opt(IDL.Nat64) +}); +export const ApproveArgs = IDL.Record({ + fee: IDL.Opt(IDL.Nat), + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Opt(IDL.Nat64), + amount: IDL.Nat, + expected_allowance: IDL.Opt(IDL.Nat), + expires_at: IDL.Opt(IDL.Nat64), + spender: Account +}); +export const ApproveError = IDL.Variant({ + GenericError: IDL.Record({ message: IDL.Text, error_code: IDL.Nat }), + TemporarilyUnavailable: IDL.Null, + Duplicate: IDL.Record({ duplicate_of: IDL.Nat }), + BadFee: IDL.Record({ expected_fee: IDL.Nat }), + AllowanceChanged: IDL.Record({ current_allowance: IDL.Nat }), + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + TooOld: IDL.Null, + Expired: IDL.Record({ ledger_time: IDL.Nat64 }), + InsufficientFunds: IDL.Record({ balance: IDL.Nat }) +}); +export const ApproveResult = IDL.Variant({ + Ok: IDL.Nat, + Err: ApproveError +}); +export const TransferFromArgs = IDL.Record({ + to: Account, + fee: IDL.Opt(IDL.Nat), + spender_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + from: Account, + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Opt(IDL.Nat64), + amount: IDL.Nat +}); +export const TransferFromError = IDL.Variant({ + GenericError: IDL.Record({ message: IDL.Text, error_code: IDL.Nat }), + TemporarilyUnavailable: IDL.Null, + InsufficientAllowance: IDL.Record({ allowance: IDL.Nat }), + BadBurn: IDL.Record({ min_burn_amount: IDL.Nat }), + Duplicate: IDL.Record({ duplicate_of: IDL.Nat }), + BadFee: IDL.Record({ expected_fee: IDL.Nat }), + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + TooOld: IDL.Null, + InsufficientFunds: IDL.Record({ balance: IDL.Nat }) +}); +export const TransferFromResult = IDL.Variant({ + Ok: IDL.Nat, + Err: TransferFromError +}); +export const idlFactory: idlFactory = ({ IDL }) => { + const SupportedStandard = IDL.Record({ url: IDL.Text, name: IDL.Text }); + const Account = IDL.Record({ + owner: IDL.Principal, + subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)) + }); + const AllowanceArgs = IDL.Record({ + account: Account, + spender: Account + }); + const AllowanceResult = IDL.Record({ + allowance: IDL.Nat, + expires_at: IDL.Opt(IDL.Nat64) + }); + const ApproveArgs = IDL.Record({ + fee: IDL.Opt(IDL.Nat), + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Opt(IDL.Nat64), + amount: IDL.Nat, + expected_allowance: IDL.Opt(IDL.Nat), + expires_at: IDL.Opt(IDL.Nat64), + spender: Account + }); + const ApproveError = IDL.Variant({ + GenericError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TemporarilyUnavailable: IDL.Null, + Duplicate: IDL.Record({ duplicate_of: IDL.Nat }), + BadFee: IDL.Record({ expected_fee: IDL.Nat }), + AllowanceChanged: IDL.Record({ current_allowance: IDL.Nat }), + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + TooOld: IDL.Null, + Expired: IDL.Record({ ledger_time: IDL.Nat64 }), + InsufficientFunds: IDL.Record({ balance: IDL.Nat }) + }); + const ApproveResult = IDL.Variant({ Ok: IDL.Nat, Err: ApproveError }); + const TransferFromArgs = IDL.Record({ + to: Account, + fee: IDL.Opt(IDL.Nat), + spender_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + from: Account, + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Opt(IDL.Nat64), + amount: IDL.Nat + }); + const TransferFromError = IDL.Variant({ + GenericError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TemporarilyUnavailable: IDL.Null, + InsufficientAllowance: IDL.Record({ allowance: IDL.Nat }), + BadBurn: IDL.Record({ min_burn_amount: IDL.Nat }), + Duplicate: IDL.Record({ duplicate_of: IDL.Nat }), + BadFee: IDL.Record({ expected_fee: IDL.Nat }), + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + TooOld: IDL.Null, + InsufficientFunds: IDL.Record({ balance: IDL.Nat }) + }); + const TransferFromResult = IDL.Variant({ + Ok: IDL.Nat, + Err: TransferFromError + }); + return IDL.Service({ + icrc1_supported_standards: IDL.Func( + [], + [IDL.Vec(SupportedStandard)], + ['query'] + ), + icrc2_allowance: IDL.Func( + [AllowanceArgs], + [AllowanceResult], + ['query'] + ), + icrc2_approve: IDL.Func([ApproveArgs], [ApproveResult], []), + icrc2_transfer_from: IDL.Func( + [TransferFromArgs], + [TransferFromResult], + [] + ) + }); +}; +export const init: init = () => { + return []; +}; diff --git a/canisters/icrc_3/ICRC-3.did b/canisters/icrc_3/ICRC-3.did new file mode 100644 index 0000000000..196d515337 --- /dev/null +++ b/canisters/icrc_3/ICRC-3.did @@ -0,0 +1,59 @@ +// Taken from: https://github.com/dfinity/ICRC-1/blob/effeeaa89d8dd75ce3b2215b9c36eed98dafb7a8/standards/ICRC-3/ICRC-3.did + +type Value = variant { + Blob : blob; + Text : text; + Nat : nat; + Int : int; + Array : vec Value; + Map : vec record { text; Value }; +}; + +type GetArchivesArgs = record { + // The last archive seen by the client. + // The Ledger will return archives coming + // after this one if set, otherwise it + // will return the first archives. + from : opt principal; +}; + +type GetArchivesResult = vec record { + // The id of the archive + canister_id : principal; + + // The first block in the archive + start : nat; + + // The last block in the archive + end : nat; +}; + +type GetBlocksArgs = vec record { start : nat; length : nat }; + +type GetBlocksResult = record { + // Total number of blocks in the + // block log + log_length : nat; + + blocks : vec record { id : nat; block: Value }; + + archived_blocks : vec record { + args : GetBlocksArgs; + callback : func (GetBlocksArgs) -> (GetBlocksResult) query; + }; +}; + +type DataCertificate = record { + // See https://internetcomputer.org/docs/current/references/ic-interface-spec#certification + certificate : blob; + + // CBOR encoded hash_tree + hash_tree : blob; +}; + +service : { + icrc3_get_archives : (GetArchivesArgs) -> (GetArchivesResult) query; + icrc3_get_tip_certificate : () -> (opt DataCertificate) query; + icrc3_get_blocks : (GetBlocksArgs) -> (GetBlocksResult) query; + icrc3_supported_block_types : () -> (vec record { block_type : text; url : text }) query; +}; diff --git a/canisters/icrc_3/LICENSE b/canisters/icrc_3/LICENSE new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/canisters/icrc_3/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/canisters/icrc_3/index.ts b/canisters/icrc_3/index.ts new file mode 100644 index 0000000000..3e718500b9 --- /dev/null +++ b/canisters/icrc_3/index.ts @@ -0,0 +1,155 @@ +import { ActorMethod } from '@dfinity/agent'; +import { IDL } from '@dfinity/candid'; +import { Principal } from '@dfinity/principal'; +export interface DataCertificate { + certificate: Uint8Array | number[]; + hash_tree: Uint8Array | number[]; +} +export interface GetArchivesArgs { + from: [] | [Principal]; +} +export type GetArchivesResult = Array<{ + end: bigint; + canister_id: Principal; + start: bigint; +}>; +export type GetBlocksArgs = Array<{ start: bigint; length: bigint }>; +export interface GetBlocksResult { + log_length: bigint; + blocks: Array<{ id: bigint; block: Value }>; + archived_blocks: Array<{ + args: GetBlocksArgs; + callback: [Principal, string]; + }>; +} +export type Value = + | { Int: bigint } + | { Map: Array<[string, Value]> } + | { Nat: bigint } + | { Blob: Uint8Array | number[] } + | { Text: string } + | { Array: Array }; +export interface _SERVICE { + icrc3_get_archives: ActorMethod<[GetArchivesArgs], GetArchivesResult>; + icrc3_get_blocks: ActorMethod<[GetBlocksArgs], GetBlocksResult>; + icrc3_get_tip_certificate: ActorMethod<[], [] | [DataCertificate]>; + icrc3_supported_block_types: ActorMethod< + [], + Array<{ url: string; block_type: string }> + >; +} +export type idlFactory = IDL.InterfaceFactory; +export type init = (args: { IDL: typeof IDL }) => IDL.Type[]; +export const GetBlocksResult = IDL.Rec(); +export const Value = IDL.Rec(); +export const GetArchivesArgs = IDL.Record({ from: IDL.Opt(IDL.Principal) }); +export const GetArchivesResult = IDL.Vec( + IDL.Record({ + end: IDL.Nat, + canister_id: IDL.Principal, + start: IDL.Nat + }) +); +export const GetBlocksArgs = IDL.Vec( + IDL.Record({ start: IDL.Nat, length: IDL.Nat }) +); +Value.fill( + IDL.Variant({ + Int: IDL.Int, + Map: IDL.Vec(IDL.Tuple(IDL.Text, Value)), + Nat: IDL.Nat, + Blob: IDL.Vec(IDL.Nat8), + Text: IDL.Text, + Array: IDL.Vec(Value) + }) +); +GetBlocksResult.fill( + IDL.Record({ + log_length: IDL.Nat, + blocks: IDL.Vec(IDL.Record({ id: IDL.Nat, block: Value })), + archived_blocks: IDL.Vec( + IDL.Record({ + args: GetBlocksArgs, + callback: IDL.Func( + [GetBlocksArgs], + [GetBlocksResult], + ['query'] + ) + }) + ) + }) +); +export const DataCertificate = IDL.Record({ + certificate: IDL.Vec(IDL.Nat8), + hash_tree: IDL.Vec(IDL.Nat8) +}); +export const idlFactory: idlFactory = ({ IDL }) => { + const GetBlocksResult = IDL.Rec(); + const Value = IDL.Rec(); + const GetArchivesArgs = IDL.Record({ from: IDL.Opt(IDL.Principal) }); + const GetArchivesResult = IDL.Vec( + IDL.Record({ + end: IDL.Nat, + canister_id: IDL.Principal, + start: IDL.Nat + }) + ); + const GetBlocksArgs = IDL.Vec( + IDL.Record({ start: IDL.Nat, length: IDL.Nat }) + ); + Value.fill( + IDL.Variant({ + Int: IDL.Int, + Map: IDL.Vec(IDL.Tuple(IDL.Text, Value)), + Nat: IDL.Nat, + Blob: IDL.Vec(IDL.Nat8), + Text: IDL.Text, + Array: IDL.Vec(Value) + }) + ); + GetBlocksResult.fill( + IDL.Record({ + log_length: IDL.Nat, + blocks: IDL.Vec(IDL.Record({ id: IDL.Nat, block: Value })), + archived_blocks: IDL.Vec( + IDL.Record({ + args: GetBlocksArgs, + callback: IDL.Func( + [GetBlocksArgs], + [GetBlocksResult], + ['query'] + ) + }) + ) + }) + ); + const DataCertificate = IDL.Record({ + certificate: IDL.Vec(IDL.Nat8), + hash_tree: IDL.Vec(IDL.Nat8) + }); + return IDL.Service({ + icrc3_get_archives: IDL.Func( + [GetArchivesArgs], + [GetArchivesResult], + ['query'] + ), + icrc3_get_blocks: IDL.Func( + [GetBlocksArgs], + [GetBlocksResult], + ['query'] + ), + icrc3_get_tip_certificate: IDL.Func( + [], + [IDL.Opt(DataCertificate)], + ['query'] + ), + icrc3_supported_block_types: IDL.Func( + [], + [IDL.Vec(IDL.Record({ url: IDL.Text, block_type: IDL.Text }))], + ['query'] + ) + }); +}; +export const init: init = () => { + return []; +}; diff --git a/canisters/icrc_37/ICRC-37.did b/canisters/icrc_37/ICRC-37.did new file mode 100644 index 0000000000..7ab067602c --- /dev/null +++ b/canisters/icrc_37/ICRC-37.did @@ -0,0 +1,152 @@ +// Taken from: https://github.com/dfinity/ICRC/blob/946bd6518acb2aafd1828b93dfde9e47657fd758/ICRCs/ICRC-37/ICRC-37.did + +type Subaccount = blob; + +type Account = record { owner : principal; subaccount : opt Subaccount }; + +type ApprovalInfo = record { + spender : Account; // Approval is given to an ICRC Account + from_subaccount : opt blob; // The subaccount the token can be transferred out from with the approval + expires_at : opt nat64; + memo : opt blob; + created_at_time : nat64; +}; + +type ApproveTokenArg = record { + token_id : nat; + approval_info : ApprovalInfo; +}; + +type ApproveTokenResult = variant { + Ok : nat; // Transaction index for successful approval + Err : ApproveTokenError; +}; + +type ApproveTokenError = variant { + InvalidSpender; + Unauthorized; + NonExistingTokenId; + TooOld; + CreatedInFuture : record { ledger_time: nat64 }; + GenericError : record { error_code : nat; message : text }; + GenericBatchError : record { error_code : nat; message : text }; +}; + +type ApproveCollectionArg = record { + approval_info : ApprovalInfo; +}; + +type ApproveCollectionResult = variant { + Ok : nat; // Transaction index for successful approval + Err : ApproveCollectionError; +}; + +type ApproveCollectionError = variant { + InvalidSpender; + TooOld; + CreatedInFuture : record { ledger_time: nat64 }; + GenericError : record { error_code : nat; message : text }; + GenericBatchError : record { error_code : nat; message : text }; +}; + +type RevokeTokenApprovalArg = record { + spender : opt Account; // null revokes matching approvals for all spenders + from_subaccount : opt blob; // null refers to the default subaccount + token_id : nat; + memo : opt blob; + created_at_time : opt nat64; +}; + +type RevokeTokenApprovalResponse = variant { + Ok : nat; // Transaction index for successful approval revocation + Err : RevokeTokenApprovalError; +}; + +type RevokeTokenApprovalError = variant { + ApprovalDoesNotExist; + Unauthorized; + NonExistingTokenId; + TooOld; + CreatedInFuture : record { ledger_time: nat64 }; + GenericError : record { error_code : nat; message : text }; + GenericBatchError : record { error_code : nat; message : text }; +}; + +type RevokeCollectionApprovalArg = record { + spender : opt Account; // null revokes approvals for all spenders that match the remaining parameters + from_subaccount : opt blob; // null refers to the default subaccount + memo : opt blob; + created_at_time : opt nat64; +}; + +type RevokeCollectionApprovalResult = variant { + Ok : nat; // Transaction index for successful approval revocation + Err : RevokeCollectionApprovalError; +}; + +type RevokeCollectionApprovalError = variant { + ApprovalDoesNotExist; + TooOld; + CreatedInFuture : record { ledger_time: nat64 }; + GenericError : record { error_code : nat; message : text }; + GenericBatchError : record { error_code : nat; message : text }; +}; + +type IsApprovedArg = record { + spender : Account; + from_subaccount : opt blob; + token_id : nat; +}; + +type TokenApproval = record { + token_id : nat; + approval_info : ApprovalInfo; +}; + +type CollectionApproval = ApprovalInfo; + +type TransferFromArg = record { + spender_subaccount: opt blob; // The subaccount of the caller (used to identify the spender) + from : Account; + to : Account; + token_id : nat; + memo : opt blob; + created_at_time : opt nat64; +}; + +type TransferFromResult = variant { + Ok : nat; // Transaction index for successful transfer + Err : TransferFromError; +}; + +type TransferFromError = variant { + InvalidRecipient; + Unauthorized; + NonExistingTokenId; + TooOld; + CreatedInFuture : record { ledger_time: nat64 }; + Duplicate : record { duplicate_of : nat }; + GenericError : record { error_code : nat; message : text }; + GenericBatchError : record { error_code : nat; message : text }; +}; + +service : { + icrc37_max_approvals_per_token_or_collection : () -> (opt nat) query; + icrc37_max_revoke_approvals : () -> (opt nat) query; + icrc37_approve_tokens : (vec ApproveTokenArg) + -> (vec opt ApproveTokenResult); + icrc37_approve_collection : (vec ApproveCollectionArg) + -> (vec opt ApproveCollectionError); + icrc37_revoke_token_approvals: (vec RevokeTokenApprovalArg) + -> (vec opt RevokeTokenApprovalResponse); + icrc37_revoke_collection_approvals: (vec RevokeCollectionApprovalArg) + -> (vec opt RevokeCollectionApprovalResult); + icrc37_is_approved : (vec IsApprovedArg) + -> (vec bool) query; + icrc37_get_token_approvals : (token_id : nat, prev : opt TokenApproval, take : opt nat) + -> (vec TokenApproval) query; + icrc37_get_collection_approvals : (owner : Account, prev : opt CollectionApproval, take : opt nat) + -> (vec CollectionApproval) query; + icrc37_transfer_from : (vec TransferFromArg) + -> (vec opt TransferFromResult); +} diff --git a/canisters/icrc_37/LICENSE b/canisters/icrc_37/LICENSE new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/canisters/icrc_37/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/canisters/icrc_37/index.ts b/canisters/icrc_37/index.ts new file mode 100644 index 0000000000..43f52ab952 --- /dev/null +++ b/canisters/icrc_37/index.ts @@ -0,0 +1,465 @@ +import { ActorMethod } from '@dfinity/agent'; +import { IDL } from '@dfinity/candid'; +import { Principal } from '@dfinity/principal'; +export interface Account { + owner: Principal; + subaccount: [] | [Subaccount]; +} +export interface ApprovalInfo { + memo: [] | [Uint8Array | number[]]; + from_subaccount: [] | [Uint8Array | number[]]; + created_at_time: bigint; + expires_at: [] | [bigint]; + spender: Account; +} +export interface ApproveCollectionArg { + approval_info: ApprovalInfo; +} +export type ApproveCollectionError = + | { + GenericError: { message: string; error_code: bigint }; + } + | { InvalidSpender: null } + | { CreatedInFuture: { ledger_time: bigint } } + | { GenericBatchError: { message: string; error_code: bigint } } + | { TooOld: null }; +export type ApproveCollectionResult = + | { Ok: bigint } + | { Err: ApproveCollectionError }; +export interface ApproveTokenArg { + token_id: bigint; + approval_info: ApprovalInfo; +} +export type ApproveTokenError = + | { + GenericError: { message: string; error_code: bigint }; + } + | { InvalidSpender: null } + | { NonExistingTokenId: null } + | { Unauthorized: null } + | { CreatedInFuture: { ledger_time: bigint } } + | { GenericBatchError: { message: string; error_code: bigint } } + | { TooOld: null }; +export type ApproveTokenResult = { Ok: bigint } | { Err: ApproveTokenError }; +export type CollectionApproval = ApprovalInfo; +export interface IsApprovedArg { + token_id: bigint; + from_subaccount: [] | [Uint8Array | number[]]; + spender: Account; +} +export interface RevokeCollectionApprovalArg { + memo: [] | [Uint8Array | number[]]; + from_subaccount: [] | [Uint8Array | number[]]; + created_at_time: [] | [bigint]; + spender: [] | [Account]; +} +export type RevokeCollectionApprovalError = + | { + GenericError: { message: string; error_code: bigint }; + } + | { CreatedInFuture: { ledger_time: bigint } } + | { ApprovalDoesNotExist: null } + | { GenericBatchError: { message: string; error_code: bigint } } + | { TooOld: null }; +export type RevokeCollectionApprovalResult = + | { Ok: bigint } + | { Err: RevokeCollectionApprovalError }; +export interface RevokeTokenApprovalArg { + token_id: bigint; + memo: [] | [Uint8Array | number[]]; + from_subaccount: [] | [Uint8Array | number[]]; + created_at_time: [] | [bigint]; + spender: [] | [Account]; +} +export type RevokeTokenApprovalError = + | { + GenericError: { message: string; error_code: bigint }; + } + | { NonExistingTokenId: null } + | { Unauthorized: null } + | { CreatedInFuture: { ledger_time: bigint } } + | { ApprovalDoesNotExist: null } + | { GenericBatchError: { message: string; error_code: bigint } } + | { TooOld: null }; +export type RevokeTokenApprovalResponse = + | { Ok: bigint } + | { Err: RevokeTokenApprovalError }; +export type Subaccount = Uint8Array | number[]; +export interface TokenApproval { + token_id: bigint; + approval_info: ApprovalInfo; +} +export interface TransferFromArg { + to: Account; + spender_subaccount: [] | [Uint8Array | number[]]; + token_id: bigint; + from: Account; + memo: [] | [Uint8Array | number[]]; + created_at_time: [] | [bigint]; +} +export type TransferFromError = + | { + GenericError: { message: string; error_code: bigint }; + } + | { Duplicate: { duplicate_of: bigint } } + | { NonExistingTokenId: null } + | { Unauthorized: null } + | { CreatedInFuture: { ledger_time: bigint } } + | { InvalidRecipient: null } + | { GenericBatchError: { message: string; error_code: bigint } } + | { TooOld: null }; +export type TransferFromResult = { Ok: bigint } | { Err: TransferFromError }; +export interface _SERVICE { + icrc37_approve_collection: ActorMethod< + [Array], + Array<[] | [ApproveCollectionError]> + >; + icrc37_approve_tokens: ActorMethod< + [Array], + Array<[] | [ApproveTokenResult]> + >; + icrc37_get_collection_approvals: ActorMethod< + [Account, [] | [CollectionApproval], [] | [bigint]], + Array + >; + icrc37_get_token_approvals: ActorMethod< + [bigint, [] | [TokenApproval], [] | [bigint]], + Array + >; + icrc37_is_approved: ActorMethod<[Array], Array>; + icrc37_max_approvals_per_token_or_collection: ActorMethod< + [], + [] | [bigint] + >; + icrc37_max_revoke_approvals: ActorMethod<[], [] | [bigint]>; + icrc37_revoke_collection_approvals: ActorMethod< + [Array], + Array<[] | [RevokeCollectionApprovalResult]> + >; + icrc37_revoke_token_approvals: ActorMethod< + [Array], + Array<[] | [RevokeTokenApprovalResponse]> + >; + icrc37_transfer_from: ActorMethod< + [Array], + Array<[] | [TransferFromResult]> + >; +} +export type idlFactory = IDL.InterfaceFactory; +export type init = (args: { IDL: typeof IDL }) => IDL.Type[]; +export const Subaccount = IDL.Vec(IDL.Nat8); +export const Account = IDL.Record({ + owner: IDL.Principal, + subaccount: IDL.Opt(Subaccount) +}); +export const ApprovalInfo = IDL.Record({ + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Nat64, + expires_at: IDL.Opt(IDL.Nat64), + spender: Account +}); +export const ApproveCollectionArg = IDL.Record({ + approval_info: ApprovalInfo +}); +export const ApproveCollectionError = IDL.Variant({ + GenericError: IDL.Record({ message: IDL.Text, error_code: IDL.Nat }), + InvalidSpender: IDL.Null, + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + GenericBatchError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TooOld: IDL.Null +}); +export const ApproveTokenArg = IDL.Record({ + token_id: IDL.Nat, + approval_info: ApprovalInfo +}); +export const ApproveTokenError = IDL.Variant({ + GenericError: IDL.Record({ message: IDL.Text, error_code: IDL.Nat }), + InvalidSpender: IDL.Null, + NonExistingTokenId: IDL.Null, + Unauthorized: IDL.Null, + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + GenericBatchError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TooOld: IDL.Null +}); +export const ApproveTokenResult = IDL.Variant({ + Ok: IDL.Nat, + Err: ApproveTokenError +}); +export const CollectionApproval = ApprovalInfo; +export const TokenApproval = IDL.Record({ + token_id: IDL.Nat, + approval_info: ApprovalInfo +}); +export const IsApprovedArg = IDL.Record({ + token_id: IDL.Nat, + from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + spender: Account +}); +export const RevokeCollectionApprovalArg = IDL.Record({ + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Opt(IDL.Nat64), + spender: IDL.Opt(Account) +}); +export const RevokeCollectionApprovalError = IDL.Variant({ + GenericError: IDL.Record({ message: IDL.Text, error_code: IDL.Nat }), + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + ApprovalDoesNotExist: IDL.Null, + GenericBatchError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TooOld: IDL.Null +}); +export const RevokeCollectionApprovalResult = IDL.Variant({ + Ok: IDL.Nat, + Err: RevokeCollectionApprovalError +}); +export const RevokeTokenApprovalArg = IDL.Record({ + token_id: IDL.Nat, + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Opt(IDL.Nat64), + spender: IDL.Opt(Account) +}); +export const RevokeTokenApprovalError = IDL.Variant({ + GenericError: IDL.Record({ message: IDL.Text, error_code: IDL.Nat }), + NonExistingTokenId: IDL.Null, + Unauthorized: IDL.Null, + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + ApprovalDoesNotExist: IDL.Null, + GenericBatchError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TooOld: IDL.Null +}); +export const RevokeTokenApprovalResponse = IDL.Variant({ + Ok: IDL.Nat, + Err: RevokeTokenApprovalError +}); +export const TransferFromArg = IDL.Record({ + to: Account, + spender_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + token_id: IDL.Nat, + from: Account, + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Opt(IDL.Nat64) +}); +export const TransferFromError = IDL.Variant({ + GenericError: IDL.Record({ message: IDL.Text, error_code: IDL.Nat }), + Duplicate: IDL.Record({ duplicate_of: IDL.Nat }), + NonExistingTokenId: IDL.Null, + Unauthorized: IDL.Null, + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + InvalidRecipient: IDL.Null, + GenericBatchError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TooOld: IDL.Null +}); +export const TransferFromResult = IDL.Variant({ + Ok: IDL.Nat, + Err: TransferFromError +}); +export const idlFactory: idlFactory = ({ IDL }) => { + const Subaccount = IDL.Vec(IDL.Nat8); + const Account = IDL.Record({ + owner: IDL.Principal, + subaccount: IDL.Opt(Subaccount) + }); + const ApprovalInfo = IDL.Record({ + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Nat64, + expires_at: IDL.Opt(IDL.Nat64), + spender: Account + }); + const ApproveCollectionArg = IDL.Record({ approval_info: ApprovalInfo }); + const ApproveCollectionError = IDL.Variant({ + GenericError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + InvalidSpender: IDL.Null, + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + GenericBatchError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TooOld: IDL.Null + }); + const ApproveTokenArg = IDL.Record({ + token_id: IDL.Nat, + approval_info: ApprovalInfo + }); + const ApproveTokenError = IDL.Variant({ + GenericError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + InvalidSpender: IDL.Null, + NonExistingTokenId: IDL.Null, + Unauthorized: IDL.Null, + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + GenericBatchError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TooOld: IDL.Null + }); + const ApproveTokenResult = IDL.Variant({ + Ok: IDL.Nat, + Err: ApproveTokenError + }); + const CollectionApproval = ApprovalInfo; + const TokenApproval = IDL.Record({ + token_id: IDL.Nat, + approval_info: ApprovalInfo + }); + const IsApprovedArg = IDL.Record({ + token_id: IDL.Nat, + from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + spender: Account + }); + const RevokeCollectionApprovalArg = IDL.Record({ + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Opt(IDL.Nat64), + spender: IDL.Opt(Account) + }); + const RevokeCollectionApprovalError = IDL.Variant({ + GenericError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + ApprovalDoesNotExist: IDL.Null, + GenericBatchError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TooOld: IDL.Null + }); + const RevokeCollectionApprovalResult = IDL.Variant({ + Ok: IDL.Nat, + Err: RevokeCollectionApprovalError + }); + const RevokeTokenApprovalArg = IDL.Record({ + token_id: IDL.Nat, + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Opt(IDL.Nat64), + spender: IDL.Opt(Account) + }); + const RevokeTokenApprovalError = IDL.Variant({ + GenericError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + NonExistingTokenId: IDL.Null, + Unauthorized: IDL.Null, + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + ApprovalDoesNotExist: IDL.Null, + GenericBatchError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TooOld: IDL.Null + }); + const RevokeTokenApprovalResponse = IDL.Variant({ + Ok: IDL.Nat, + Err: RevokeTokenApprovalError + }); + const TransferFromArg = IDL.Record({ + to: Account, + spender_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + token_id: IDL.Nat, + from: Account, + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Opt(IDL.Nat64) + }); + const TransferFromError = IDL.Variant({ + GenericError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + Duplicate: IDL.Record({ duplicate_of: IDL.Nat }), + NonExistingTokenId: IDL.Null, + Unauthorized: IDL.Null, + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + InvalidRecipient: IDL.Null, + GenericBatchError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TooOld: IDL.Null + }); + const TransferFromResult = IDL.Variant({ + Ok: IDL.Nat, + Err: TransferFromError + }); + return IDL.Service({ + icrc37_approve_collection: IDL.Func( + [IDL.Vec(ApproveCollectionArg)], + [IDL.Vec(IDL.Opt(ApproveCollectionError))], + [] + ), + icrc37_approve_tokens: IDL.Func( + [IDL.Vec(ApproveTokenArg)], + [IDL.Vec(IDL.Opt(ApproveTokenResult))], + [] + ), + icrc37_get_collection_approvals: IDL.Func( + [Account, IDL.Opt(CollectionApproval), IDL.Opt(IDL.Nat)], + [IDL.Vec(CollectionApproval)], + ['query'] + ), + icrc37_get_token_approvals: IDL.Func( + [IDL.Nat, IDL.Opt(TokenApproval), IDL.Opt(IDL.Nat)], + [IDL.Vec(TokenApproval)], + ['query'] + ), + icrc37_is_approved: IDL.Func( + [IDL.Vec(IsApprovedArg)], + [IDL.Vec(IDL.Bool)], + ['query'] + ), + icrc37_max_approvals_per_token_or_collection: IDL.Func( + [], + [IDL.Opt(IDL.Nat)], + ['query'] + ), + icrc37_max_revoke_approvals: IDL.Func( + [], + [IDL.Opt(IDL.Nat)], + ['query'] + ), + icrc37_revoke_collection_approvals: IDL.Func( + [IDL.Vec(RevokeCollectionApprovalArg)], + [IDL.Vec(IDL.Opt(RevokeCollectionApprovalResult))], + [] + ), + icrc37_revoke_token_approvals: IDL.Func( + [IDL.Vec(RevokeTokenApprovalArg)], + [IDL.Vec(IDL.Opt(RevokeTokenApprovalResponse))], + [] + ), + icrc37_transfer_from: IDL.Func( + [IDL.Vec(TransferFromArg)], + [IDL.Vec(IDL.Opt(TransferFromResult))], + [] + ) + }); +}; +export const init: init = () => { + return []; +}; diff --git a/canisters/icrc_7/ICRC-7.did b/canisters/icrc_7/ICRC-7.did new file mode 100644 index 0000000000..a095f4ca58 --- /dev/null +++ b/canisters/icrc_7/ICRC-7.did @@ -0,0 +1,67 @@ +// Taken from: https://github.com/dfinity/ICRC/blob/946bd6518acb2aafd1828b93dfde9e47657fd758/ICRCs/ICRC-7/ICRC-7.did + +type Subaccount = blob; + +type Account = record { owner : principal; subaccount : opt Subaccount }; + +// Generic value in accordance with ICRC-3 +type Value = variant { + Blob : blob; + Text : text; + Nat : nat; + Int : int; + Array : vec Value; + Map : vec record { text; Value }; +}; + +type TransferArg = record { + from_subaccount: opt blob; // The subaccount to transfer the token from + to : Account; + token_id : nat; + memo : opt blob; + created_at_time : opt nat64; +}; + +type TransferResult = variant { + Ok : nat; // Transaction index for successful transfer + Err : TransferError; +}; + +type TransferError = variant { + NonExistingTokenId; + InvalidRecipient; + Unauthorized; + TooOld; + CreatedInFuture : record { ledger_time: nat64 }; + Duplicate : record { duplicate_of : nat }; + GenericError : record { error_code : nat; message : text }; + GenericBatchError : record { error_code : nat; message : text }; +}; + +service : { + icrc7_collection_metadata : () -> (vec record { text; Value } ) query; + icrc7_symbol : () -> (text) query; + icrc7_name : () -> (text) query; + icrc7_description : () -> (opt text) query; + icrc7_logo : () -> (opt text) query; + icrc7_total_supply : () -> (nat) query; + icrc7_supply_cap : () -> (opt nat) query; + icrc7_max_query_batch_size : () -> (opt nat) query; + icrc7_max_update_batch_size : () -> (opt nat) query; + icrc7_default_take_value : () -> (opt nat) query; + icrc7_max_take_value : () -> (opt nat) query; + icrc7_max_memo_size : () -> (opt nat) query; + icrc7_atomic_batch_transfers : () -> (opt bool) query; + icrc7_tx_window : () -> (opt nat) query; + icrc7_permitted_drift : () -> (opt nat) query; + icrc7_token_metadata : (token_ids : vec nat) + -> (vec opt vec record { text; Value }) query; + icrc7_owner_of : (token_ids : vec nat) + -> (vec opt Account) query; + icrc7_balance_of : (vec Account) -> (vec nat) query; + icrc7_tokens : (prev : opt nat, take : opt nat) + -> (vec nat) query; + icrc7_tokens_of : (account : Account, prev : opt nat, take : opt nat) + -> (vec nat) query; + icrc7_transfer : (vec TransferArg) -> (vec opt TransferResult); +} diff --git a/canisters/icrc_7/LICENSE b/canisters/icrc_7/LICENSE new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/canisters/icrc_7/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/canisters/icrc_7/index.ts b/canisters/icrc_7/index.ts new file mode 100644 index 0000000000..d74c046e39 --- /dev/null +++ b/canisters/icrc_7/index.ts @@ -0,0 +1,212 @@ +import { ActorMethod } from '@dfinity/agent'; +import { IDL } from '@dfinity/candid'; +import { Principal } from '@dfinity/principal'; +export interface Account { + owner: Principal; + subaccount: [] | [Subaccount]; +} +export type Subaccount = Uint8Array | number[]; +export interface TransferArg { + to: Account; + token_id: bigint; + memo: [] | [Uint8Array | number[]]; + from_subaccount: [] | [Uint8Array | number[]]; + created_at_time: [] | [bigint]; +} +export type TransferError = + | { + GenericError: { message: string; error_code: bigint }; + } + | { Duplicate: { duplicate_of: bigint } } + | { NonExistingTokenId: null } + | { Unauthorized: null } + | { CreatedInFuture: { ledger_time: bigint } } + | { InvalidRecipient: null } + | { GenericBatchError: { message: string; error_code: bigint } } + | { TooOld: null }; +export type TransferResult = { Ok: bigint } | { Err: TransferError }; +export type Value = + | { Int: bigint } + | { Map: Array<[string, Value]> } + | { Nat: bigint } + | { Blob: Uint8Array | number[] } + | { Text: string } + | { Array: Array }; +export interface _SERVICE { + icrc7_atomic_batch_transfers: ActorMethod<[], [] | [boolean]>; + icrc7_balance_of: ActorMethod<[Array], Array>; + icrc7_collection_metadata: ActorMethod<[], Array<[string, Value]>>; + icrc7_default_take_value: ActorMethod<[], [] | [bigint]>; + icrc7_description: ActorMethod<[], [] | [string]>; + icrc7_logo: ActorMethod<[], [] | [string]>; + icrc7_max_memo_size: ActorMethod<[], [] | [bigint]>; + icrc7_max_query_batch_size: ActorMethod<[], [] | [bigint]>; + icrc7_max_take_value: ActorMethod<[], [] | [bigint]>; + icrc7_max_update_batch_size: ActorMethod<[], [] | [bigint]>; + icrc7_name: ActorMethod<[], string>; + icrc7_owner_of: ActorMethod<[Array], Array<[] | [Account]>>; + icrc7_permitted_drift: ActorMethod<[], [] | [bigint]>; + icrc7_supply_cap: ActorMethod<[], [] | [bigint]>; + icrc7_symbol: ActorMethod<[], string>; + icrc7_token_metadata: ActorMethod< + [Array], + Array<[] | [Array<[string, Value]>]> + >; + icrc7_tokens: ActorMethod<[[] | [bigint], [] | [bigint]], Array>; + icrc7_tokens_of: ActorMethod< + [Account, [] | [bigint], [] | [bigint]], + Array + >; + icrc7_total_supply: ActorMethod<[], bigint>; + icrc7_transfer: ActorMethod< + [Array], + Array<[] | [TransferResult]> + >; + icrc7_tx_window: ActorMethod<[], [] | [bigint]>; +} +export type idlFactory = IDL.InterfaceFactory; +export type init = (args: { IDL: typeof IDL }) => IDL.Type[]; +export const Value = IDL.Rec(); +export const Subaccount = IDL.Vec(IDL.Nat8); +export const Account = IDL.Record({ + owner: IDL.Principal, + subaccount: IDL.Opt(Subaccount) +}); +Value.fill( + IDL.Variant({ + Int: IDL.Int, + Map: IDL.Vec(IDL.Tuple(IDL.Text, Value)), + Nat: IDL.Nat, + Blob: IDL.Vec(IDL.Nat8), + Text: IDL.Text, + Array: IDL.Vec(Value) + }) +); +export const TransferArg = IDL.Record({ + to: Account, + token_id: IDL.Nat, + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Opt(IDL.Nat64) +}); +export const TransferError = IDL.Variant({ + GenericError: IDL.Record({ message: IDL.Text, error_code: IDL.Nat }), + Duplicate: IDL.Record({ duplicate_of: IDL.Nat }), + NonExistingTokenId: IDL.Null, + Unauthorized: IDL.Null, + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + InvalidRecipient: IDL.Null, + GenericBatchError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TooOld: IDL.Null +}); +export const TransferResult = IDL.Variant({ + Ok: IDL.Nat, + Err: TransferError +}); +export const idlFactory: idlFactory = ({ IDL }) => { + const Value = IDL.Rec(); + const Subaccount = IDL.Vec(IDL.Nat8); + const Account = IDL.Record({ + owner: IDL.Principal, + subaccount: IDL.Opt(Subaccount) + }); + Value.fill( + IDL.Variant({ + Int: IDL.Int, + Map: IDL.Vec(IDL.Tuple(IDL.Text, Value)), + Nat: IDL.Nat, + Blob: IDL.Vec(IDL.Nat8), + Text: IDL.Text, + Array: IDL.Vec(Value) + }) + ); + const TransferArg = IDL.Record({ + to: Account, + token_id: IDL.Nat, + memo: IDL.Opt(IDL.Vec(IDL.Nat8)), + from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), + created_at_time: IDL.Opt(IDL.Nat64) + }); + const TransferError = IDL.Variant({ + GenericError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + Duplicate: IDL.Record({ duplicate_of: IDL.Nat }), + NonExistingTokenId: IDL.Null, + Unauthorized: IDL.Null, + CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), + InvalidRecipient: IDL.Null, + GenericBatchError: IDL.Record({ + message: IDL.Text, + error_code: IDL.Nat + }), + TooOld: IDL.Null + }); + const TransferResult = IDL.Variant({ Ok: IDL.Nat, Err: TransferError }); + return IDL.Service({ + icrc7_atomic_batch_transfers: IDL.Func( + [], + [IDL.Opt(IDL.Bool)], + ['query'] + ), + icrc7_balance_of: IDL.Func( + [IDL.Vec(Account)], + [IDL.Vec(IDL.Nat)], + ['query'] + ), + icrc7_collection_metadata: IDL.Func( + [], + [IDL.Vec(IDL.Tuple(IDL.Text, Value))], + ['query'] + ), + icrc7_default_take_value: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), + icrc7_description: IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), + icrc7_logo: IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), + icrc7_max_memo_size: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), + icrc7_max_query_batch_size: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), + icrc7_max_take_value: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), + icrc7_max_update_batch_size: IDL.Func( + [], + [IDL.Opt(IDL.Nat)], + ['query'] + ), + icrc7_name: IDL.Func([], [IDL.Text], ['query']), + icrc7_owner_of: IDL.Func( + [IDL.Vec(IDL.Nat)], + [IDL.Vec(IDL.Opt(Account))], + ['query'] + ), + icrc7_permitted_drift: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), + icrc7_supply_cap: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), + icrc7_symbol: IDL.Func([], [IDL.Text], ['query']), + icrc7_token_metadata: IDL.Func( + [IDL.Vec(IDL.Nat)], + [IDL.Vec(IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, Value))))], + ['query'] + ), + icrc7_tokens: IDL.Func( + [IDL.Opt(IDL.Nat), IDL.Opt(IDL.Nat)], + [IDL.Vec(IDL.Nat)], + ['query'] + ), + icrc7_tokens_of: IDL.Func( + [Account, IDL.Opt(IDL.Nat), IDL.Opt(IDL.Nat)], + [IDL.Vec(IDL.Nat)], + ['query'] + ), + icrc7_total_supply: IDL.Func([], [IDL.Nat], ['query']), + icrc7_transfer: IDL.Func( + [IDL.Vec(TransferArg)], + [IDL.Vec(IDL.Opt(TransferResult))], + [] + ), + icrc7_tx_window: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']) + }); +}; +export const init: init = () => { + return []; +}; diff --git a/tests/end_to_end/candid_rpc/class_syntax/icrc/canisters/proxy/index.ts b/tests/end_to_end/candid_rpc/class_syntax/icrc/canisters/proxy/index.ts index a4276fe946..5cb74c2d07 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/icrc/canisters/proxy/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/icrc/canisters/proxy/index.ts @@ -1,17 +1,19 @@ import { call, IDL, query, trap, update } from 'azle'; import { Account, + TransferArgs, + TransferResult, + Value +} from 'azle/canisters/icrc_1'; +import { AllowanceArgs, AllowanceResult, ApproveArgs, ApproveResult, SupportedStandard, - TransferArgs, TransferFromArgs, - TransferFromResult, - TransferResult, - Value -} from 'azle/canisters/icrc'; + TransferFromResult +} from 'azle/canisters/icrc_2'; export default class { @query([], IDL.Vec(IDL.Tuple(IDL.Text, Value)), { composite: true }) diff --git a/tests/end_to_end/candid_rpc/class_syntax/icrc/package-lock.json b/tests/end_to_end/candid_rpc/class_syntax/icrc/package-lock.json index 4a3752d908..5c6e4aef81 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/icrc/package-lock.json +++ b/tests/end_to_end/candid_rpc/class_syntax/icrc/package-lock.json @@ -17,6 +17,7 @@ } }, "../../functional_syntax/icrc": { + "name": "icrc_end_to_end_test_functional_syntax", "dev": true, "dependencies": { "azle": "0.24.1"