From 4c3f3b2a46d5e090239d3db7f706c8fc32c7b62a Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 1 Jun 2022 12:35:09 +0000 Subject: [PATCH] add Itoka --- src/constants/canisters.ts | 2 + src/constants/standards.ts | 3 +- src/idls/itoka.did.ts | 300 ++++++++++++++++++ src/index.ts | 7 +- src/interfaces/itoka.ts | 195 ++++++++++++ src/interfaces/nft.ts | 4 +- src/registries/nfts_registry.ts | 5 +- .../nft_standards/ic_punks.ts | 2 +- src/standard_wrappers/nft_standards/itoka.ts | 49 +++ 9 files changed, 560 insertions(+), 7 deletions(-) create mode 100644 src/idls/itoka.did.ts create mode 100644 src/interfaces/itoka.ts create mode 100644 src/standard_wrappers/nft_standards/itoka.ts diff --git a/src/constants/canisters.ts b/src/constants/canisters.ts index 443156a..dd763d2 100644 --- a/src/constants/canisters.ts +++ b/src/constants/canisters.ts @@ -16,4 +16,6 @@ export const NFT_CANISTERS = { 'f5zsx-wqaaa-aaaaf-qaeha-cai', 'f2yud-3iaaa-aaaaf-qaehq-cai', ], + ITOKA: '4y4bz-6aaaa-aaaai-acj4a-cai', + ITOKA_ASSETS: '5avu2-qaaaa-aaaai-acjya-cai', }; diff --git a/src/constants/standards.ts b/src/constants/standards.ts index b497c3b..60a5407 100644 --- a/src/constants/standards.ts +++ b/src/constants/standards.ts @@ -13,7 +13,8 @@ export const NFT = { erc721: 'ERC721', dip721: 'DIP721', dip721v2: 'DIP721v2', - c3: 'C3' + c3: 'C3', + itoka: 'Itoka' } export default { diff --git a/src/idls/itoka.did.ts b/src/idls/itoka.did.ts new file mode 100644 index 0000000..fab19cd --- /dev/null +++ b/src/idls/itoka.did.ts @@ -0,0 +1,300 @@ +export default ({ IDL }) => { + const CustodianSetupReceipt = IDL.Variant({ + 'Ok' : IDL.Text, + 'Err' : IDL.Text, + }); + const Errors = IDL.Variant({ + 'Unauthorized' : IDL.Null, + 'TokenNotExist' : IDL.Null, + 'InvalidOperator' : IDL.Null, + }); + const TxReceipt = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : Errors }); + const MusicSetupReceipt = IDL.Variant({ + 'Ok' : IDL.Tuple(IDL.Nat, IDL.Text), + 'Err' : Errors, + }); + const AlbumCoverLocation = IDL.Record({ + 'icp' : IDL.Text, + 'ipfs' : IDL.Text, + }); + const Attribute = IDL.Record({ + 'bpm' : IDL.Nat, + 'key' : IDL.Text, + 'backbone' : IDL.Text, + 'collection' : IDL.Text, + 'name' : IDL.Text, + 'genre' : IDL.Vec(IDL.Text), + }); + const AudioLocation = IDL.Record({ 'icp' : IDL.Text, 'ipfs' : IDL.Text }); + const TokenMetadata__1 = IDL.Record({ + 'tokenIdentifier' : IDL.Text, + 'albumCoverLocation' : AlbumCoverLocation, + 'albumCoverType' : IDL.Text, + 'rawAudioType' : IDL.Text, + 'attributes' : Attribute, + 'previewAudioType' : IDL.Text, + 'previewAudioLocation' : AudioLocation, + 'rawAudioLocation' : AudioLocation, + 'compressedAudioType' : IDL.Text, + 'compressedAudioLocation' : AudioLocation, + }); + const Operation = IDL.Variant({ + 'setStreamingRoyalty' : IDL.Null, + 'retriveDecryptionKey' : IDL.Null, + 'transferFrom' : IDL.Null, + 'setDecryptionKey' : IDL.Null, + 'setAudioCompressedSrc' : IDL.Null, + 'setAudioRawSrc' : IDL.Null, + 'retriveAudioCompressedSrc' : IDL.Null, + 'retriveAudioPreviewSrc' : IDL.Null, + 'burn' : IDL.Null, + 'approveAll' : IDL.Null, + 'setAudioPreviewSrc' : IDL.Null, + 'mint' : IDL.Opt(TokenMetadata__1), + 'approve' : IDL.Null, + 'upgrade' : IDL.Null, + 'setMetadata' : IDL.Null, + 'setTranscationFee' : IDL.Null, + 'retriveAudioRawSrc' : IDL.Null, + 'transfer' : IDL.Null, + 'revokeAll' : IDL.Null, + }); + const Time = IDL.Int; + const UpgradeHistory = IDL.Record({ + 'upgrade_time' : Time, + 'message' : IDL.Text, + }); + const Record = IDL.Variant({ + 'transcationFee' : IDL.Nat, + 'metadata' : IDL.Opt(TokenMetadata__1), + 'user' : IDL.Principal, + 'secret' : IDL.Text, + 'commit' : UpgradeHistory, + }); + const TxRecord = IDL.Record({ + 'op' : Operation, + 'to' : Record, + 'tokenIndex' : IDL.Opt(IDL.Nat), + 'from' : Record, + 'timestamp' : Time, + 'caller' : IDL.Principal, + 'index' : IDL.Nat, + }); + const StreamingResult = IDL.Variant({ + 'AudioSrc' : IDL.Opt(IDL.Text), + 'StreamingTimes' : IDL.Nat, + }); + const StreamingReceipt = IDL.Variant({ + 'Ok' : StreamingResult, + 'Err' : Errors, + }); + const TokenInfoExt = IDL.Record({ + 'owner' : IDL.Principal, + 'metadata' : IDL.Opt(TokenMetadata__1), + 'operator' : IDL.Opt(IDL.Principal), + 'timestamp' : Time, + 'index' : IDL.Nat, + }); + const Metadata = IDL.Record({ + 'owner' : IDL.Principal, + 'desc' : IDL.Text, + 'logo' : IDL.Text, + 'name' : IDL.Text, + 'totalSupply' : IDL.Nat, + 'created_at' : Time, + 'cycles' : IDL.Nat, + 'upgraded_at' : Time, + 'custodians' : IDL.Vec(IDL.Principal), + 'symbol' : IDL.Text, + }); + const UserInfoExt = IDL.Record({ + 'allowedTokens' : IDL.Vec(IDL.Nat), + 'tokens' : IDL.Vec(IDL.Nat), + 'operators' : IDL.Vec(IDL.Principal), + 'allowedBy' : IDL.Vec(IDL.Principal), + }); + const TokenMetadata = IDL.Record({ + 'tokenIdentifier' : IDL.Text, + 'albumCoverLocation' : AlbumCoverLocation, + 'albumCoverType' : IDL.Text, + 'rawAudioType' : IDL.Text, + 'attributes' : Attribute, + 'previewAudioType' : IDL.Text, + 'previewAudioLocation' : AudioLocation, + 'rawAudioLocation' : AudioLocation, + 'compressedAudioType' : IDL.Text, + 'compressedAudioLocation' : AudioLocation, + }); + const MintResult = IDL.Variant({ + 'Ok' : IDL.Tuple(IDL.Nat, IDL.Nat), + 'Err' : Errors, + }); + const DecryptionKey = IDL.Record({ + 'iv' : IDL.Text, + 'privateKey' : IDL.Text, + }); + const DecryptionKeyReceipt = IDL.Variant({ + 'Ok' : IDL.Opt(DecryptionKey), + 'Err' : Errors, + }); + const NFToken = IDL.Service({ + 'addCustodian' : IDL.Func([IDL.Principal], [CustodianSetupReceipt], []), + 'approve' : IDL.Func([IDL.Nat, IDL.Principal], [TxReceipt], []), + 'availableCycles' : IDL.Func([], [IDL.Nat], ['query']), + 'balanceOf' : IDL.Func([IDL.Principal], [IDL.Nat], ['query']), + 'burn' : IDL.Func([IDL.Nat], [TxReceipt], []), + 'commit' : IDL.Func([IDL.Text], [MusicSetupReceipt], []), + 'desc' : IDL.Func([], [IDL.Text], ['query']), + 'getAllHolders' : IDL.Func([], [IDL.Vec(IDL.Principal)], ['query']), + 'getAllMusicSetupHistory' : IDL.Func([], [IDL.Vec(TxRecord)], ['query']), + 'getAllTokenAudioTotalStreamingAmount' : IDL.Func( + [], + [StreamingReceipt], + ['query'], + ), + 'getAllTokens' : IDL.Func([], [IDL.Vec(TokenInfoExt)], ['query']), + 'getAllUpgradeHistory' : IDL.Func([], [IDL.Vec(TxRecord)], ['query']), + 'getHolderStreamingAmount' : IDL.Func( + [IDL.Principal], + [IDL.Nat], + ['query'], + ), + 'getLatestMusicSetupHistory' : IDL.Func([], [TxRecord], ['query']), + 'getLatestStreamingHistory' : IDL.Func([], [TxRecord], ['query']), + 'getLatestUpgradeHistory' : IDL.Func([], [TxRecord], ['query']), + 'getMetadata' : IDL.Func([], [Metadata], ['query']), + 'getOperator' : IDL.Func([IDL.Nat], [IDL.Principal], ['query']), + 'getStreamingHistory' : IDL.Func([IDL.Nat], [TxRecord], ['query']), + 'getStreamingHistorys' : IDL.Func( + [IDL.Nat, IDL.Nat], + [IDL.Vec(TxRecord)], + ['query'], + ), + 'getTokenAudioCompressedStreamingAmount' : IDL.Func( + [IDL.Nat], + [StreamingReceipt], + ['query'], + ), + 'getTokenAudioPreviewStreamingAmount' : IDL.Func( + [IDL.Nat], + [StreamingReceipt], + ['query'], + ), + 'getTokenAudioRawStreamingAmount' : IDL.Func( + [IDL.Nat], + [StreamingReceipt], + ['query'], + ), + 'getTokenAudioTotalStreamingAmount' : IDL.Func( + [IDL.Nat], + [StreamingReceipt], + ['query'], + ), + 'getTokenInfo' : IDL.Func([IDL.Nat], [TokenInfoExt], ['query']), + 'getTransaction' : IDL.Func([IDL.Nat], [TxRecord], ['query']), + 'getTransactions' : IDL.Func( + [IDL.Nat, IDL.Nat], + [IDL.Vec(TxRecord)], + ['query'], + ), + 'getTranscationFee' : IDL.Func([], [IDL.Nat], ['query']), + 'getUserInfo' : IDL.Func([IDL.Principal], [UserInfoExt], ['query']), + 'getUserStreamingHistorys' : IDL.Func( + [IDL.Principal, IDL.Nat, IDL.Nat], + [IDL.Vec(TxRecord)], + ['query'], + ), + 'getUserTokens' : IDL.Func( + [IDL.Principal], + [IDL.Vec(TokenInfoExt)], + ['query'], + ), + 'getUserTransactionAmount' : IDL.Func( + [IDL.Principal], + [IDL.Nat], + ['query'], + ), + 'getUserTransactions' : IDL.Func( + [IDL.Principal, IDL.Nat, IDL.Nat], + [IDL.Vec(TxRecord)], + ['query'], + ), + 'getUserlisteningAmount' : IDL.Func([IDL.Principal], [IDL.Nat], ['query']), + 'getUserlistenings' : IDL.Func( + [IDL.Principal, IDL.Nat, IDL.Nat], + [IDL.Vec(TxRecord)], + ['query'], + ), + 'historySize' : IDL.Func([], [IDL.Nat], ['query']), + 'historySize_streaming' : IDL.Func([], [IDL.Nat], ['query']), + 'isApprovedForAll' : IDL.Func( + [IDL.Principal, IDL.Principal], + [IDL.Bool], + ['query'], + ), + 'logo' : IDL.Func([], [IDL.Text], ['query']), + 'mint' : IDL.Func( + [IDL.Principal, IDL.Opt(TokenMetadata)], + [MintResult], + [], + ), + 'name' : IDL.Func([], [IDL.Text], ['query']), + 'ownerOf' : IDL.Func([IDL.Nat], [IDL.Principal], ['query']), + 'removeCustodian' : IDL.Func([IDL.Principal], [CustodianSetupReceipt], []), + 'retriveAudioCompressedSrc' : IDL.Func( + [IDL.Nat, IDL.Principal], + [StreamingReceipt], + [], + ), + 'retriveAudioPreviewSrc' : IDL.Func( + [IDL.Nat, IDL.Principal], + [StreamingReceipt], + [], + ), + 'retriveDecryptionKey' : IDL.Func([IDL.Nat], [DecryptionKeyReceipt], []), + 'retriveRawAudioSrc' : IDL.Func( + [IDL.Nat, IDL.Principal], + [StreamingReceipt], + [], + ), + 'setApprovalForAll' : IDL.Func([IDL.Principal, IDL.Bool], [TxReceipt], []), + 'setAudioCompressedSrc' : IDL.Func( + [IDL.Nat, IDL.Text], + [MusicSetupReceipt], + [], + ), + 'setAudioPreviewSrc' : IDL.Func( + [IDL.Nat, IDL.Text], + [MusicSetupReceipt], + [], + ), + 'setAudioRawSrc' : IDL.Func([IDL.Nat, IDL.Text], [MusicSetupReceipt], []), + 'setDecryptionKey' : IDL.Func( + [IDL.Nat, IDL.Text, IDL.Text], + [MusicSetupReceipt], + [], + ), + 'setTokenMetadata' : IDL.Func([IDL.Nat, TokenMetadata], [TxReceipt], []), + 'setTranscationFee' : IDL.Func([IDL.Nat], [TxReceipt], []), + 'symbol' : IDL.Func([], [IDL.Text], ['query']), + 'totalSupply' : IDL.Func([], [IDL.Nat], ['query']), + 'transfer' : IDL.Func([IDL.Principal, IDL.Nat], [TxReceipt], []), + 'transferFrom' : IDL.Func( + [IDL.Principal, IDL.Principal, IDL.Nat], + [TxReceipt], + [], + ), + 'who_are_custodians' : IDL.Func([], [IDL.Vec(IDL.Principal)], ['query']), + }); + return NFToken; +}; +export const init = ({ IDL }) => { + return [ + IDL.Text, + IDL.Text, + IDL.Text, + IDL.Text, + IDL.Principal, + IDL.Opt(IDL.Nat), + ]; +}; diff --git a/src/index.ts b/src/index.ts index c0a4cac..bc7b2d4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,11 @@ import NFT from './standard_wrappers/nft_standards/default'; import EXT from './standard_wrappers/nft_standards/ext'; import ICPunks from './standard_wrappers/nft_standards/ic_punks'; +import Itoka from './standard_wrappers/nft_standards/itoka'; export * from './registries'; -export * from './interfaces/nft'; -export * from './interfaces/token'; +export * from './interfaces/nft'; +export * from './interfaces/token'; export * as NFTInterfaces from './interfaces/nft'; -export * as TokenInterfaces from './interfaces/token' +export * as TokenInterfaces from './interfaces/token'; export { default as standards } from './constants/standards'; diff --git a/src/interfaces/itoka.ts b/src/interfaces/itoka.ts new file mode 100644 index 0000000..c413a9a --- /dev/null +++ b/src/interfaces/itoka.ts @@ -0,0 +1,195 @@ +import type { Principal } from '@dfinity/principal'; +import type { ActorMethod } from '@dfinity/agent'; + +export interface AlbumCoverLocation { 'icp' : string, 'ipfs' : string } +export interface Attribute { + 'bpm' : bigint, + 'key' : string, + 'backbone' : string, + 'collection' : string, + 'name' : string, + 'genre' : Array, +} +export interface AudioLocation { 'icp' : string, 'ipfs' : string } +export type CustodianSetupReceipt = { 'Ok' : string } | + { 'Err' : string }; +export interface DecryptionKey { 'iv' : string, 'privateKey' : string } +export type DecryptionKeyReceipt = { 'Ok' : [] | [DecryptionKey] } | + { 'Err' : Errors }; +export type Errors = { 'Unauthorized' : null } | + { 'TokenNotExist' : null } | + { 'InvalidOperator' : null }; +export interface Metadata { + 'owner' : Principal, + 'desc' : string, + 'logo' : string, + 'name' : string, + 'totalSupply' : bigint, + 'created_at' : Time, + 'cycles' : bigint, + 'upgraded_at' : Time, + 'custodians' : Array, + 'symbol' : string, +} +export type MintResult = { 'Ok' : [bigint, bigint] } | + { 'Err' : Errors }; +export type MusicSetupReceipt = { 'Ok' : [bigint, string] } | + { 'Err' : Errors }; +export interface NFToken { + 'addCustodian' : ActorMethod<[Principal], CustodianSetupReceipt>, + 'approve' : ActorMethod<[bigint, Principal], TxReceipt>, + 'availableCycles' : ActorMethod<[], bigint>, + 'balanceOf' : ActorMethod<[Principal], bigint>, + 'burn' : ActorMethod<[bigint], TxReceipt>, + 'commit' : ActorMethod<[string], MusicSetupReceipt>, + 'desc' : ActorMethod<[], string>, + 'getAllHolders' : ActorMethod<[], Array>, + 'getAllMusicSetupHistory' : ActorMethod<[], Array>, + 'getAllTokenAudioTotalStreamingAmount' : ActorMethod<[], StreamingReceipt>, + 'getAllTokens' : ActorMethod<[], Array>, + 'getAllUpgradeHistory' : ActorMethod<[], Array>, + 'getHolderStreamingAmount' : ActorMethod<[Principal], bigint>, + 'getLatestMusicSetupHistory' : ActorMethod<[], TxRecord>, + 'getLatestStreamingHistory' : ActorMethod<[], TxRecord>, + 'getLatestUpgradeHistory' : ActorMethod<[], TxRecord>, + 'getMetadata' : ActorMethod<[], Metadata>, + 'getOperator' : ActorMethod<[bigint], Principal>, + 'getStreamingHistory' : ActorMethod<[bigint], TxRecord>, + 'getStreamingHistorys' : ActorMethod<[bigint, bigint], Array>, + 'getTokenAudioCompressedStreamingAmount' : ActorMethod< + [bigint], + StreamingReceipt, + >, + 'getTokenAudioPreviewStreamingAmount' : ActorMethod< + [bigint], + StreamingReceipt, + >, + 'getTokenAudioRawStreamingAmount' : ActorMethod<[bigint], StreamingReceipt>, + 'getTokenAudioTotalStreamingAmount' : ActorMethod<[bigint], StreamingReceipt>, + 'getTokenInfo' : ActorMethod<[bigint], TokenInfoExt>, + 'getTransaction' : ActorMethod<[bigint], TxRecord>, + 'getTransactions' : ActorMethod<[bigint, bigint], Array>, + 'getTranscationFee' : ActorMethod<[], bigint>, + 'getUserInfo' : ActorMethod<[Principal], UserInfoExt>, + 'getUserStreamingHistorys' : ActorMethod< + [Principal, bigint, bigint], + Array, + >, + 'getUserTokens' : ActorMethod<[Principal], Array>, + 'getUserTransactionAmount' : ActorMethod<[Principal], bigint>, + 'getUserTransactions' : ActorMethod< + [Principal, bigint, bigint], + Array, + >, + 'getUserlisteningAmount' : ActorMethod<[Principal], bigint>, + 'getUserlistenings' : ActorMethod< + [Principal, bigint, bigint], + Array, + >, + 'historySize' : ActorMethod<[], bigint>, + 'historySize_streaming' : ActorMethod<[], bigint>, + 'isApprovedForAll' : ActorMethod<[Principal, Principal], boolean>, + 'logo' : ActorMethod<[], string>, + 'mint' : ActorMethod<[Principal, [] | [TokenMetadata]], MintResult>, + 'name' : ActorMethod<[], string>, + 'ownerOf' : ActorMethod<[bigint], Principal>, + 'removeCustodian' : ActorMethod<[Principal], CustodianSetupReceipt>, + 'retriveAudioCompressedSrc' : ActorMethod< + [bigint, Principal], + StreamingReceipt, + >, + 'retriveAudioPreviewSrc' : ActorMethod<[bigint, Principal], StreamingReceipt>, + 'retriveDecryptionKey' : ActorMethod<[bigint], DecryptionKeyReceipt>, + 'retriveRawAudioSrc' : ActorMethod<[bigint, Principal], StreamingReceipt>, + 'setApprovalForAll' : ActorMethod<[Principal, boolean], TxReceipt>, + 'setAudioCompressedSrc' : ActorMethod<[bigint, string], MusicSetupReceipt>, + 'setAudioPreviewSrc' : ActorMethod<[bigint, string], MusicSetupReceipt>, + 'setAudioRawSrc' : ActorMethod<[bigint, string], MusicSetupReceipt>, + 'setDecryptionKey' : ActorMethod<[bigint, string, string], MusicSetupReceipt>, + 'setTokenMetadata' : ActorMethod<[bigint, TokenMetadata], TxReceipt>, + 'setTranscationFee' : ActorMethod<[bigint], TxReceipt>, + 'symbol' : ActorMethod<[], string>, + 'totalSupply' : ActorMethod<[], bigint>, + 'transfer' : ActorMethod<[Principal, bigint], TxReceipt>, + 'transferFrom' : ActorMethod<[Principal, Principal, bigint], TxReceipt>, + 'who_are_custodians' : ActorMethod<[], Array>, +} +export type Operation = { 'setStreamingRoyalty' : null } | + { 'retriveDecryptionKey' : null } | + { 'transferFrom' : null } | + { 'setDecryptionKey' : null } | + { 'setAudioCompressedSrc' : null } | + { 'setAudioRawSrc' : null } | + { 'retriveAudioCompressedSrc' : null } | + { 'retriveAudioPreviewSrc' : null } | + { 'burn' : null } | + { 'approveAll' : null } | + { 'setAudioPreviewSrc' : null } | + { 'mint' : [] | [TokenMetadata__1] } | + { 'approve' : null } | + { 'upgrade' : null } | + { 'setMetadata' : null } | + { 'setTranscationFee' : null } | + { 'retriveAudioRawSrc' : null } | + { 'transfer' : null } | + { 'revokeAll' : null }; +export type Record = { 'transcationFee' : bigint } | + { 'metadata' : [] | [TokenMetadata__1] } | + { 'user' : Principal } | + { 'secret' : string } | + { 'commit' : UpgradeHistory }; +export type StreamingReceipt = { 'Ok' : StreamingResult } | + { 'Err' : Errors }; +export type StreamingResult = { 'AudioSrc' : [] | [string] } | + { 'StreamingTimes' : bigint }; +export type Time = bigint; +export interface TokenInfoExt { + 'owner' : Principal, + 'metadata' : [] | [TokenMetadata__1], + 'operator' : [] | [Principal], + 'timestamp' : Time, + 'index' : bigint, +} +export interface TokenMetadata { + 'tokenIdentifier' : string, + 'albumCoverLocation' : AlbumCoverLocation, + 'albumCoverType' : string, + 'rawAudioType' : string, + 'attributes' : Attribute, + 'previewAudioType' : string, + 'previewAudioLocation' : AudioLocation, + 'rawAudioLocation' : AudioLocation, + 'compressedAudioType' : string, + 'compressedAudioLocation' : AudioLocation, +} +export interface TokenMetadata__1 { + 'tokenIdentifier' : string, + 'albumCoverLocation' : AlbumCoverLocation, + 'albumCoverType' : string, + 'rawAudioType' : string, + 'attributes' : Attribute, + 'previewAudioType' : string, + 'previewAudioLocation' : AudioLocation, + 'rawAudioLocation' : AudioLocation, + 'compressedAudioType' : string, + 'compressedAudioLocation' : AudioLocation, +} +export type TxReceipt = { 'Ok' : bigint } | + { 'Err' : Errors }; +export interface TxRecord { + 'op' : Operation, + 'to' : Record, + 'tokenIndex' : [] | [bigint], + 'from' : Record, + 'timestamp' : Time, + 'caller' : Principal, + 'index' : bigint, +} +export interface UpgradeHistory { 'upgrade_time' : Time, 'message' : string } +export interface UserInfoExt { + 'allowedTokens' : Array, + 'tokens' : Array, + 'operators' : Array, + 'allowedBy' : Array, +} +export default interface _SERVICE extends NFToken {} diff --git a/src/interfaces/nft.ts b/src/interfaces/nft.ts index bb35c10..b17b029 100644 --- a/src/interfaces/nft.ts +++ b/src/interfaces/nft.ts @@ -6,6 +6,7 @@ import DIP721v2 from '../standard_wrappers/nft_standards/dip_721_v2'; import EXT from '../standard_wrappers/nft_standards/ext'; import CCC from '../standard_wrappers/nft_standards/ccc'; import ICPunks from '../standard_wrappers/nft_standards/ic_punks'; +import Itoka from '../standard_wrappers/nft_standards/itoka'; export type NFTStandards = | typeof EXT @@ -13,7 +14,8 @@ export type NFTStandards = | typeof DepartureLabs | typeof DIP721 | typeof DIP721v2 - | typeof CCC; + | typeof CCC + | typeof Itoka; export interface DABCollection { icon: string; diff --git a/src/registries/nfts_registry.ts b/src/registries/nfts_registry.ts index 07d992f..7ddab0a 100644 --- a/src/registries/nfts_registry.ts +++ b/src/registries/nfts_registry.ts @@ -22,6 +22,8 @@ import Registry from './standard_registry'; import { generateActor } from '../utils/actorFactory'; import { formatMetadata, FormattedMetadata } from '../utils/registry'; import CCC from '../standard_wrappers/nft_standards/ccc'; +import Itoka from '../standard_wrappers/nft_standards/itoka'; + const CANISTER_ID = 'ctqxp-yyaaa-aaaah-abbda-cai'; const BATCH_AMOUNT = 5; @@ -33,7 +35,8 @@ const NFT_STANDARDS: { [key: string]: NFTStandards } = { [NFTStandard.erc721]: DIP721, [NFTStandard.dip721]: DIP721, [NFTStandard.dip721v2]: DIP721v2, - [NFTStandard.c3]: CCC + [NFTStandard.c3]: CCC, + [NFTStandard.itoka]: Itoka }; interface GetBatchedNFTsParams { diff --git a/src/standard_wrappers/nft_standards/ic_punks.ts b/src/standard_wrappers/nft_standards/ic_punks.ts index 5182bd1..fa16f17 100644 --- a/src/standard_wrappers/nft_standards/ic_punks.ts +++ b/src/standard_wrappers/nft_standards/ic_punks.ts @@ -6,7 +6,7 @@ import IDL from '../../idls/icpunks.did'; import NFT from './default'; import { NFTDetails } from '../../interfaces/nft'; import { NFT_CANISTERS } from '../../constants/canisters'; -import { NFT as NFTStandard} from '../../constants/standards'; +import { NFT as NFTStandard } from '../../constants/standards'; const getICPBunnyCanisterId = (index) => NFT_CANISTERS.ICP_BUNNY_STORAGE[index % 10]; diff --git a/src/standard_wrappers/nft_standards/itoka.ts b/src/standard_wrappers/nft_standards/itoka.ts new file mode 100644 index 0000000..6f85bfb --- /dev/null +++ b/src/standard_wrappers/nft_standards/itoka.ts @@ -0,0 +1,49 @@ +import { Actor, ActorSubclass, HttpAgent } from '@dfinity/agent'; +import { Principal } from '@dfinity/principal'; + +import ITOKA_NFT, { TokenMetadata, TokenInfoExt } from '../../interfaces/itoka'; +import IDL from '../../idls/itoka.did'; +import NFT from './default'; +import { NFTDetails } from '../../interfaces/nft'; +import { NFT as NFTStandard } from '../../constants/standards'; + +export default class ITOKA extends NFT { + standard = NFTStandard.itoka; + + actor: ActorSubclass; + + constructor(canisterId: string, agent: HttpAgent) { + super(canisterId, agent); + + this.actor = Actor.createActor(IDL, { + agent, + canisterId, + }); + } + + async getUserTokens(principal: Principal): Promise { + const tokensData = await this.actor.getUserTokens(principal); + return tokensData.map((token) => this.serializeTokenData(token)); + } + + async transfer(to: Principal, tokenIndex: number): Promise { + const TxReceipt = await this.actor.transfer(to, BigInt(tokenIndex)); + if ('Err' in TxReceipt) throw new Error(Object.keys(TxReceipt.Err)[0]); + } + + async details(tokenIndex: number): Promise { + const tokenData = await this.actor.getTokenInfo(BigInt(tokenIndex)); + return this.serializeTokenData(tokenData); + } + + private serializeTokenData = (tokenData: TokenInfoExt): NFTDetails => ({ + index: BigInt(tokenData.index), + canister: this.canisterId, + id: tokenData.metadata[0]?.tokenIdentifier, + name: tokenData.metadata[0]?.attributes.name, + url: tokenData.metadata[0]?.albumCoverLocation.icp as string, + metadata: tokenData.metadata, + standard: this.standard, + owner: tokenData.owner, + }); +}