├── .eslintignore ├── .eslintrc.js ├── .gitattributes ├── .gitignore ├── .npmignore ├── .npmrc ├── .prettierrc.js ├── LICENSE ├── README.md ├── jest.config.cjs ├── package.json ├── src ├── constants │ ├── canisters.ts │ ├── index.ts │ └── standards.ts ├── idls │ ├── c3.did.ts │ ├── dab_nfts.did.ts │ ├── dab_registries │ │ ├── address_book.did.ts │ │ ├── canister_registry.did.ts │ │ ├── nft_registry.did.ts │ │ ├── registry_standard.did.ts │ │ └── token_registry.did.ts │ ├── departure_labs.did.ts │ ├── dip_20.did.ts │ ├── dip_721.did.ts │ ├── drc_20.did.ts │ ├── ext.did.ts │ ├── icpunks.did.ts │ ├── icrc_1.did.ts │ ├── icrc_7.did.ts │ ├── ledger.did.ts │ ├── nft_origyn.did.ts │ ├── wicp.did.ts │ └── xtc.did.ts ├── index.ts ├── interfaces │ ├── c3.ts │ ├── dab_nfts.ts │ ├── dab_registries │ │ ├── address_book.ts │ │ ├── canister_registry.ts │ │ ├── nft_registry.ts │ │ ├── registry_standard.ts │ │ └── token_registry.ts │ ├── departure_labs.ts │ ├── dip_20.ts │ ├── dip_721.ts │ ├── drc_20.ts │ ├── ext.ts │ ├── icpunks.ts │ ├── icrc_1.ts │ ├── icrc_7.ts │ ├── ledger.ts │ ├── nft.ts │ ├── nft_origyn.ts │ ├── token.ts │ ├── wicp.ts │ └── xtc.ts ├── registries │ ├── address_book.ts │ ├── canister_registry.ts │ ├── index.ts │ ├── nfts_registry.ts │ ├── standard_registry.ts │ └── token_registry.ts ├── standard_wrappers │ ├── nft_standards │ │ ├── ccc.ts │ │ ├── default.ts │ │ ├── departure_labs.ts │ │ ├── dip_721.ts │ │ ├── ext.ts │ │ ├── ic_punks.ts │ │ ├── icrc_7.ts │ │ └── nft_origyn.ts │ └── token_standards │ │ ├── dip20Methods.ts │ │ ├── drc20Methods.ts │ │ ├── extMethods.ts │ │ ├── icpStandardMethods.ts │ │ ├── icrc1Methods.ts │ │ ├── index.ts │ │ ├── methods.ts │ │ ├── rosettaMethods.ts │ │ ├── wicpMethods.ts │ │ └── xtcMethods.ts └── utils │ ├── account.ts │ ├── actorFactory.ts │ ├── number.ts │ ├── registry.ts │ └── validations.ts ├── tsconfig.json └── yarn.lock /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | *.spec.ts 4 | *.mock.ts 5 | *.mocks.ts -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | plugins: ['@typescript-eslint', 'eslint-plugin-import'], 4 | extends: [ 5 | 'plugin:@typescript-eslint/recommended', 6 | 'airbnb/base', 7 | 'prettier/@typescript-eslint', 8 | 'plugin:prettier/recommended', 9 | 'eslint:recommended', 10 | ], 11 | parserOptions: { 12 | ecmaVersion: 6, 13 | sourceType: 'module', 14 | ecmaFeatures: { 15 | jsx: true, 16 | modules: true, 17 | }, 18 | }, 19 | rules: { 20 | 'func-names': 0, 21 | '@typescript-eslint/no-namespace': 0, 22 | 'import/extensions': [ 23 | 'error', 24 | 'ignorePackages', 25 | { 26 | js: 'never', 27 | jsx: 'never', 28 | ts: 'never', 29 | tsx: 'never', 30 | }, 31 | ], 32 | 'no-useless-constructor': 'off', 33 | 'no-empty-function': 'off', 34 | }, 35 | env: { 36 | node: true, 37 | commonjs: true, 38 | jest: true, 39 | es2020: true, 40 | }, 41 | settings: { 42 | 'indent': ['error', 2], 43 | 'import/extensions': ['.js', '.jsx', '.ts', '.tsx'], 44 | 'import/parsers': { 45 | '@typescript-eslint/parser': ['.ts', '.tsx'], 46 | }, 47 | 'import/resolver': { 48 | node: { 49 | extensions: ['.js', '.jsx', '.ts', '.tsx'], 50 | }, 51 | }, 52 | }, 53 | }; 54 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | # Oclif 107 | oclif.manifest.json 108 | 109 | .idea 110 | 111 | manual.ts -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /jest.config.js 2 | /tsconfig.json 3 | /.env 4 | /src 5 | /mock-files 6 | /coverage 7 | /dist/jest/*.js 8 | /dist/**/*.spec.js 9 | /dist/**/*.mock.js 10 | /src/manual.ts -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | @psychedelic:registry=https://npm.pkg.github.com 2 | # //npm.pkg.github.com/:_authToken=${PAT} 3 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | trailingComma: "es5", 3 | tabWidth: 2, 4 | semi: true, 5 | singleQuote: true, 6 | useTabs: false 7 | }; -------------------------------------------------------------------------------- /jest.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | roots: ['/src'], 3 | transform: { 4 | '^.+\\.tsx?$': 'ts-jest' 5 | }, 6 | transformIgnorePatterns: ['/node_modules/.*'], 7 | setupFilesAfterEnv: ['/src/jest/setup-jest.ts'], 8 | collectCoverage: true, 9 | verbose: true, 10 | coverageReporters: ['html'], 11 | coveragePathIgnorePatterns: ['/src/jest/*', '.mock.ts', '.idl', '/src/utils/storage'], 12 | preset: 'ts-jest', 13 | testEnvironment: 'node' 14 | }; 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@funded-labs/dab-js", 3 | "version": "2.0.0", 4 | "description": "JS adapter for DAB", 5 | "main": "dist/index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git@github.com:Psychedelic/DAB-js.git" 9 | }, 10 | "keywords": [ 11 | "ic", 12 | "dfinity", 13 | "plug", 14 | "fleek", 15 | "psychedelic", 16 | "crypto", 17 | "wallet" 18 | ], 19 | "author": "Psychedelic", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/Psychedelic/DAB-js/issues" 23 | }, 24 | "homepage": "https://github.com/Psychedelic/DAB-js#readme", 25 | "scripts": { 26 | "build": "npm run clean && npm run compile", 27 | "clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo", 28 | "compile": "tsc -b tsconfig.json", 29 | "test": "jest", 30 | "lint": "eslint --ext ts,js ./src", 31 | "watch": "tsc --watch", 32 | "package:publish": "npm run build && npm publish", 33 | "publish:local": "npm run build && npm publish --@funded-labs:registry=${LOCAL_REGISTRY:=http://localhost:4873/}", 34 | "unpublish:local": "npm unpublish @funded-labs/dab-js --@funded-labs:registry=${LOCAL_REGISTRY:=http://localhost:4873/} --force" 35 | }, 36 | "devDependencies": { 37 | "@typescript-eslint/eslint-plugin": "^4.32.0", 38 | "eslint": "^7.2.0", 39 | "eslint-config-airbnb-base": "14.2.1", 40 | "eslint-plugin-import": "^2.22.1", 41 | "jest": "^27.1.1", 42 | "ts-jest": "^27.0.5", 43 | "ts-node": "^10.2.1", 44 | "typescript": "^4.4.2" 45 | }, 46 | "dependencies": { 47 | "@dfinity/agent": "^2.3.0", 48 | "@dfinity/candid": "^2.3.0", 49 | "@dfinity/principal": "^2.3.0", 50 | "@types/node": "^20.10.6", 51 | "buffer-crc32": "^0.2.13", 52 | "crypto-js": "^4.1.1" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/constants/canisters.ts: -------------------------------------------------------------------------------- 1 | export const NFT_CANISTERS = { 2 | WRAPPED_PUNKS: 'bxdf4-baaaa-aaaah-qaruq-cai', 3 | WRAPPED_DRIP: '3db6u-aiaaa-aaaah-qbjbq-cai', 4 | IC_PUNKS: 'qcg3w-tyaaa-aaaah-qakea-cai', 5 | IC_DRIP: 'd3ttm-qaaaa-aaaai-qam4a-cai', 6 | ICP_BUNNY_MAIN: 'xkbqi-2qaaa-aaaah-qbpqq-cai', 7 | ICP_BUNNY_STORAGE: [ 8 | 'efqhu-yqaaa-aaaaf-qaeda-cai', 9 | 'ecrba-viaaa-aaaaf-qaedq-cai', 10 | 'fp7fo-2aaaa-aaaaf-qaeea-cai', 11 | 'fi6d2-xyaaa-aaaaf-qaeeq-cai', 12 | 'fb5ig-bqaaa-aaaaf-qaefa-cai', 13 | 'fg4os-miaaa-aaaaf-qaefq-cai', 14 | 'ft377-naaaa-aaaaf-qaega-cai', 15 | 'fu2zl-ayaaa-aaaaf-qaegq-cai', 16 | 'f5zsx-wqaaa-aaaaf-qaeha-cai', 17 | 'f2yud-3iaaa-aaaaf-qaehq-cai', 18 | ], 19 | }; 20 | -------------------------------------------------------------------------------- /src/constants/index.ts: -------------------------------------------------------------------------------- 1 | export const IC_HOST = 'https://icp0.io/'; 2 | export const KYASSHU_URL = 'https://kyasshu.plugwallet.ooo'; 3 | -------------------------------------------------------------------------------- /src/constants/standards.ts: -------------------------------------------------------------------------------- 1 | export const TOKEN = { 2 | dip20: 'DIP20', 3 | xtc: 'XTC', 4 | wicp: 'WICP', 5 | ext: 'EXT', 6 | icp: 'ICP', 7 | rosetta: 'ROSETTA', 8 | icrc1: 'ICRC1', 9 | drc20: 'DRC20', 10 | }; 11 | 12 | export const NFT = { 13 | ext: 'EXT', 14 | icpunks: 'ICPUNKS', 15 | departuresLabs: 'DEPARTURELABS', 16 | erc721: 'ERC721', 17 | dip721: 'DIP721', 18 | c3: 'C3', 19 | nftOrigyn: 'NFTORIGYN', 20 | icrc7: 'ICRC7', 21 | }; 22 | 23 | export default { 24 | TOKEN, 25 | NFT, 26 | }; 27 | -------------------------------------------------------------------------------- /src/idls/c3.did.ts: -------------------------------------------------------------------------------- 1 | export default ({ IDL }) => { 2 | const TokenIndex__1 = IDL.Nat; 3 | const TokenIndex = IDL.Nat; 4 | const TransferResponse = IDL.Variant({ 5 | 'ok' : TokenIndex, 6 | 'err' : IDL.Variant({ 7 | 'ListOnMarketPlace' : IDL.Null, 8 | 'NotAllowTransferToSelf' : IDL.Null, 9 | 'NotOwnerOrNotApprove' : IDL.Null, 10 | 'Other' : IDL.Null, 11 | }), 12 | }); 13 | 14 | const TokenDetails = IDL.Record({ 15 | 'id' : IDL.Nat, 16 | 'rarityScore' : IDL.Float64, 17 | }); 18 | 19 | const GetTokenResponse = IDL.Variant({ 20 | 'ok' : TokenDetails, 21 | 'err' : IDL.Variant({ 'NotFoundIndex' : IDL.Null }), 22 | }); 23 | const C2NFT = IDL.Service({ 24 | 'getAllNFT' : IDL.Func( 25 | [IDL.Principal], 26 | [IDL.Vec(IDL.Tuple(TokenIndex__1, IDL.Principal))], 27 | ['query'], 28 | ), 29 | 'getNftStoreCIDByIndex' : IDL.Func( 30 | [TokenIndex__1], 31 | [IDL.Principal], 32 | ['query'], 33 | ), 34 | 'getTokenById' : IDL.Func([IDL.Nat], [GetTokenResponse], ['query']), 35 | 'transferFrom' : IDL.Func( 36 | [IDL.Principal, IDL.Principal, TokenIndex__1], 37 | [TransferResponse], 38 | [], 39 | ), 40 | }); 41 | return C2NFT; 42 | }; 43 | export const init = ({ IDL }) => { 44 | return [IDL.Principal, IDL.Principal, IDL.Principal]; 45 | }; 46 | -------------------------------------------------------------------------------- /src/idls/dab_nfts.did.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/camelcase */ 2 | /* eslint-disable camelcase */ 3 | 4 | export default ({ IDL }) => { 5 | const DABCollection = IDL.Record({ 6 | 'icon' : IDL.Text, 7 | 'name' : IDL.Text, 8 | 'description' : IDL.Text, 9 | 'principal_id' : IDL.Principal, 10 | 'standard' : IDL.Text, 11 | }); 12 | const OperationError = IDL.Variant({ 13 | 'NotAuthorized' : IDL.Null, 14 | 'BadParameters' : IDL.Null, 15 | 'NonExistentItem' : IDL.Null, 16 | 'ParamatersNotPassed' : IDL.Null, 17 | }); 18 | const OperationResponse = IDL.Variant({ 19 | 'Ok' : IDL.Bool, 20 | 'Err' : OperationError, 21 | }); 22 | const NFTCanister = IDL.Record({ 23 | 'icon' : IDL.Text, 24 | 'name' : IDL.Text, 25 | 'description' : IDL.Text, 26 | 'timestamp' : IDL.Nat64, 27 | 'principal_id' : IDL.Principal, 28 | 'standard' : IDL.Text, 29 | }); 30 | return IDL.Service({ 31 | 'add' : IDL.Func([DABCollection], [OperationResponse], []), 32 | 'edit' : IDL.Func( 33 | [ 34 | IDL.Text, 35 | IDL.Opt(IDL.Principal), 36 | IDL.Opt(IDL.Text), 37 | IDL.Opt(IDL.Text), 38 | IDL.Opt(IDL.Text), 39 | ], 40 | [OperationResponse], 41 | [], 42 | ), 43 | 'get_all' : IDL.Func([], [IDL.Vec(NFTCanister)], []), 44 | 'get_canister' : IDL.Func([IDL.Text], [IDL.Opt(NFTCanister)], ['query']), 45 | 'name' : IDL.Func([], [IDL.Text], ['query']), 46 | 'remove' : IDL.Func([IDL.Text], [OperationResponse], []), 47 | }); 48 | }; 49 | export const init = () => { return []; }; -------------------------------------------------------------------------------- /src/idls/dab_registries/address_book.did.ts: -------------------------------------------------------------------------------- 1 | const addressBookIDL = ({ IDL }) => { 2 | 3 | const valueType = IDL.Variant({ 4 | 'PrincipalId': IDL.Principal, 5 | 'AccountId': IDL.Text, 6 | 'Icns': IDL.Text, 7 | }) 8 | 9 | const address = IDL.Record({ 10 | 'name' : IDL.Text, 11 | 'description' : IDL.Opt(IDL.Text), 12 | 'emoji' : IDL.Opt(IDL.Text), 13 | 'value': valueType, 14 | }); 15 | const operation_error = IDL.Variant({ 16 | 'NotAuthorized' : IDL.Null, 17 | 'BadParameters' : IDL.Null, 18 | 'Unknown' : IDL.Text, 19 | 'NonExistentItem' : IDL.Null, 20 | }); 21 | const operation_response = IDL.Variant({ 22 | 'Ok' : IDL.Null, 23 | 'Err' : operation_error, 24 | }); 25 | return IDL.Service({ 26 | 'add' : IDL.Func( 27 | [address], 28 | [operation_response], 29 | [], 30 | ), 31 | 'get_all' : IDL.Func([], [IDL.Vec(address)], []), 32 | 'name' : IDL.Func([], [IDL.Text], ['query']), 33 | 'remove' : IDL.Func([IDL.Text], [operation_response], []), 34 | }); 35 | }; 36 | 37 | export default addressBookIDL; 38 | 39 | -------------------------------------------------------------------------------- /src/idls/dab_registries/canister_registry.did.ts: -------------------------------------------------------------------------------- 1 | export default ({ IDL }) => { 2 | const detail_value = IDL.Rec(); 3 | detail_value.fill( 4 | IDL.Variant({ 5 | 'I64' : IDL.Int64, 6 | 'U64' : IDL.Nat64, 7 | 'Vec' : IDL.Vec(detail_value), 8 | 'Slice' : IDL.Vec(IDL.Nat8), 9 | 'Text' : IDL.Text, 10 | 'True' : IDL.Null, 11 | 'False' : IDL.Null, 12 | 'Float' : IDL.Float64, 13 | 'Principal' : IDL.Principal, 14 | }) 15 | ); 16 | const canister_metadata = IDL.Record({ 17 | 'thumbnail' : IDL.Text, 18 | 'name' : IDL.Text, 19 | 'frontend' : IDL.Opt(IDL.Text), 20 | 'description' : IDL.Text, 21 | 'principal_id' : IDL.Principal, 22 | 'details' : IDL.Vec(IDL.Tuple(IDL.Text, detail_value)), 23 | }); 24 | const operation_error = IDL.Variant({ 25 | 'NotAuthorized' : IDL.Null, 26 | 'BadParameters' : IDL.Null, 27 | 'Unknown' : IDL.Text, 28 | 'NonExistentItem' : IDL.Null, 29 | }); 30 | const operation_response = IDL.Variant({ 31 | 'Ok' : IDL.Opt(IDL.Text), 32 | 'Err' : operation_error, 33 | }); 34 | return IDL.Service({ 35 | 'add' : IDL.Func( 36 | [canister_metadata], 37 | [operation_response], 38 | [], 39 | ), 40 | 'get' : IDL.Func( 41 | [IDL.Principal], 42 | [IDL.Opt(canister_metadata)], 43 | ['query'], 44 | ), 45 | 'get_all' : IDL.Func([], [IDL.Vec(canister_metadata)], ['query']), 46 | 'name' : IDL.Func([], [IDL.Text], ['query']), 47 | 'remove' : IDL.Func([IDL.Principal], [operation_response], []), 48 | }); 49 | }; 50 | export const init = () => { return []; }; 51 | -------------------------------------------------------------------------------- /src/idls/dab_registries/nft_registry.did.ts: -------------------------------------------------------------------------------- 1 | export default ({ IDL }) => { 2 | const detail_value = IDL.Rec(); 3 | detail_value.fill( 4 | IDL.Variant({ 5 | 'I64' : IDL.Int64, 6 | 'U64' : IDL.Nat64, 7 | 'Vec' : IDL.Vec(detail_value), 8 | 'Slice' : IDL.Vec(IDL.Nat8), 9 | 'Text' : IDL.Text, 10 | 'True' : IDL.Null, 11 | 'False' : IDL.Null, 12 | 'Float' : IDL.Float64, 13 | 'Principal' : IDL.Principal, 14 | }) 15 | ); 16 | const nft_canister = IDL.Record({ 17 | 'thumbnail' : IDL.Text, 18 | 'name' : IDL.Text, 19 | 'frontend' : IDL.Opt(IDL.Text), 20 | 'description' : IDL.Text, 21 | 'details' : IDL.Vec(IDL.Tuple(IDL.Text, detail_value)), 22 | 'principal_id' : IDL.Principal, 23 | }); 24 | const operation_error = IDL.Variant({ 25 | 'NotAuthorized' : IDL.Null, 26 | 'BadParameters' : IDL.Null, 27 | 'Unknown' : IDL.Text, 28 | 'NonExistentItem' : IDL.Null, 29 | }); 30 | const operation_response = IDL.Variant({ 31 | 'Ok' : IDL.Opt(IDL.Text), 32 | 'Err' : operation_error, 33 | }); 34 | return IDL.Service({ 35 | 'add' : IDL.Func([nft_canister], [operation_response], []), 36 | 'get' : IDL.Func([IDL.Principal], [IDL.Opt(nft_canister)], ['query']), 37 | 'get_all' : IDL.Func([], [IDL.Vec(nft_canister)], ['query']), 38 | 'name' : IDL.Func([], [IDL.Text], ['query']), 39 | 'remove' : IDL.Func([IDL.Principal], [operation_response], []), 40 | 'set_controller' : IDL.Func([IDL.Principal], [operation_response], []), 41 | }); 42 | }; 43 | export const init = () => { return []; }; 44 | -------------------------------------------------------------------------------- /src/idls/dab_registries/registry_standard.did.ts: -------------------------------------------------------------------------------- 1 | export default ({ IDL }) => { 2 | const detail_value = IDL.Rec(); 3 | detail_value.fill( 4 | IDL.Variant({ 5 | 'I64' : IDL.Int64, 6 | 'U64' : IDL.Nat64, 7 | 'Vec' : IDL.Vec(detail_value), 8 | 'Slice' : IDL.Vec(IDL.Nat8), 9 | 'Text' : IDL.Text, 10 | 'True' : IDL.Null, 11 | 'False' : IDL.Null, 12 | 'Float' : IDL.Float64, 13 | 'Principal' : IDL.Principal, 14 | }) 15 | ); 16 | const metadata = IDL.Record({ 17 | 'thumbnail' : IDL.Text, 18 | 'name' : IDL.Text, 19 | 'frontend' : IDL.Opt(IDL.Text), 20 | 'description' : IDL.Text, 21 | 'principal_id' : IDL.Principal, 22 | 'details' : IDL.Vec(IDL.Tuple(IDL.Text, detail_value)), 23 | }); 24 | const error = IDL.Variant({ 25 | 'NotAuthorized' : IDL.Null, 26 | 'BadParameters' : IDL.Null, 27 | 'Unknown' : IDL.Text, 28 | 'NonExistantCanister' : IDL.Null, 29 | }); 30 | const response = IDL.Variant({ 'Ok' : IDL.Opt(IDL.Text), 'Err' : error }); 31 | return IDL.Service({ 32 | 'add' : IDL.Func([metadata], [response], []), 33 | 'get' : IDL.Func([IDL.Principal], [IDL.Opt(metadata)], ['query']), 34 | 'name' : IDL.Func([], [IDL.Text], ['query']), 35 | 'remove' : IDL.Func([IDL.Principal], [response], []), 36 | }); 37 | }; 38 | export const init = () => { return []; }; 39 | -------------------------------------------------------------------------------- /src/idls/dab_registries/token_registry.did.ts: -------------------------------------------------------------------------------- 1 | export default ({ IDL }) => { 2 | const detail_value = IDL.Rec(); 3 | detail_value.fill( 4 | IDL.Variant({ 5 | 'I64' : IDL.Int64, 6 | 'U64' : IDL.Nat64, 7 | 'Vec' : IDL.Vec(detail_value), 8 | 'Slice' : IDL.Vec(IDL.Nat8), 9 | 'Text' : IDL.Text, 10 | 'True' : IDL.Null, 11 | 'False' : IDL.Null, 12 | 'Float' : IDL.Float64, 13 | 'Principal' : IDL.Principal, 14 | }) 15 | ); 16 | const token = IDL.Record({ 17 | 'thumbnail' : IDL.Text, 18 | 'name' : IDL.Text, 19 | 'frontend' : IDL.Opt(IDL.Text), 20 | 'description' : IDL.Text, 21 | 'principal_id': IDL.Principal, 22 | 'details' : IDL.Vec(IDL.Tuple(IDL.Text, detail_value)), 23 | }); 24 | const operation_error = IDL.Variant({ 25 | 'NotAuthorized' : IDL.Null, 26 | 'BadParameters' : IDL.Null, 27 | 'Unknown' : IDL.Text, 28 | 'NonExistentItem' : IDL.Null, 29 | }); 30 | const operation_response = IDL.Variant({ 31 | 'Ok' : IDL.Opt(IDL.Text), 32 | 'Err' : operation_error, 33 | }); 34 | return IDL.Service({ 35 | 'add' : IDL.Func([token], [operation_response], []), 36 | 'get' : IDL.Func([IDL.Principal], [IDL.Opt(token)], ['query']), 37 | 'get_all' : IDL.Func([], [IDL.Vec(token)], ['query']), 38 | 'name' : IDL.Func([], [IDL.Text], ['query']), 39 | 'remove' : IDL.Func([IDL.Principal], [operation_response], []), 40 | 'set_controller' : IDL.Func([IDL.Principal], [operation_response], []), 41 | }); 42 | }; 43 | export const init = () => { return []; }; 44 | -------------------------------------------------------------------------------- /src/idls/departure_labs.did.ts: -------------------------------------------------------------------------------- 1 | export default ({ IDL }) => { 2 | const Property = IDL.Rec(); 3 | const Query = IDL.Rec(); 4 | const Update = IDL.Rec(); 5 | const Callback = IDL.Func([], [], []); 6 | const StagedWrite = IDL.Variant({ 7 | 'Init' : IDL.Record({ 'size' : IDL.Nat, 'callback' : IDL.Opt(Callback) }), 8 | 'Chunk' : IDL.Record({ 9 | 'chunk' : IDL.Vec(IDL.Nat8), 10 | 'callback' : IDL.Opt(Callback), 11 | }), 12 | }); 13 | const AssetRequest = IDL.Variant({ 14 | 'Put' : IDL.Record({ 15 | 'key' : IDL.Text, 16 | 'contentType' : IDL.Text, 17 | 'callback' : IDL.Opt(Callback), 18 | 'payload' : IDL.Variant({ 19 | 'StagedData' : IDL.Null, 20 | 'Payload' : IDL.Vec(IDL.Nat8), 21 | }), 22 | }), 23 | 'Remove' : IDL.Record({ 'key' : IDL.Text, 'callback' : IDL.Opt(Callback) }), 24 | 'StagedWrite' : StagedWrite, 25 | }); 26 | const AuthorizeRequest = IDL.Record({ 27 | 'p' : IDL.Principal, 28 | 'id' : IDL.Text, 29 | 'isAuthorized' : IDL.Bool, 30 | }); 31 | const Error = IDL.Variant({ 32 | 'Immutable' : IDL.Null, 33 | 'NotFound' : IDL.Null, 34 | 'Unauthorized' : IDL.Null, 35 | 'InvalidRequest' : IDL.Null, 36 | 'AuthorizedPrincipalLimitReached' : IDL.Nat, 37 | }); 38 | const Result_1 = IDL.Variant({ 'ok' : IDL.Null, 'err' : Error }); 39 | const ContractInfo = IDL.Record({ 40 | 'nft_payload_size' : IDL.Nat, 41 | 'memory_size' : IDL.Nat, 42 | 'max_live_size' : IDL.Nat, 43 | 'cycles' : IDL.Nat, 44 | 'total_minted' : IDL.Nat, 45 | 'heap_size' : IDL.Nat, 46 | 'authorized_users' : IDL.Vec(IDL.Principal), 47 | }); 48 | const TopupCallback = IDL.Func([], [], []); 49 | const Contract = IDL.Variant({ 50 | 'ContractAuthorize' : IDL.Record({ 51 | 'isAuthorized' : IDL.Bool, 52 | 'user' : IDL.Principal, 53 | }), 54 | 'Mint' : IDL.Record({ 'id' : IDL.Text, 'owner' : IDL.Principal }), 55 | }); 56 | const Token = IDL.Variant({ 57 | 'Authorize' : IDL.Record({ 58 | 'id' : IDL.Text, 59 | 'isAuthorized' : IDL.Bool, 60 | 'user' : IDL.Principal, 61 | }), 62 | 'Transfer' : IDL.Record({ 63 | 'id' : IDL.Text, 64 | 'to' : IDL.Principal, 65 | 'from' : IDL.Principal, 66 | }), 67 | }); 68 | const Message = IDL.Record({ 69 | 'topupCallback' : TopupCallback, 70 | 'createdAt' : IDL.Int, 71 | 'topupAmount' : IDL.Nat, 72 | 'event' : IDL.Variant({ 'ContractEvent' : Contract, 'TokenEvent' : Token }), 73 | }); 74 | const Callback__1 = IDL.Func([Message], [], []); 75 | const CallbackStatus = IDL.Record({ 76 | 'failedCalls' : IDL.Nat, 77 | 'failedCallsLimit' : IDL.Nat, 78 | 'callback' : IDL.Opt(Callback__1), 79 | 'noTopupCallLimit' : IDL.Nat, 80 | 'callsSinceLastTopup' : IDL.Nat, 81 | }); 82 | const ContractMetadata = IDL.Record({ 83 | 'name' : IDL.Text, 84 | 'symbol' : IDL.Text, 85 | }); 86 | const HeaderField = IDL.Tuple(IDL.Text, IDL.Text); 87 | const Request = IDL.Record({ 88 | 'url' : IDL.Text, 89 | 'method' : IDL.Text, 90 | 'body' : IDL.Vec(IDL.Nat8), 91 | 'headers' : IDL.Vec(HeaderField), 92 | }); 93 | const StreamingCallbackToken = IDL.Record({ 94 | 'key' : IDL.Text, 95 | 'index' : IDL.Nat, 96 | 'content_encoding' : IDL.Text, 97 | }); 98 | const StreamingCallbackResponse = IDL.Record({ 99 | 'token' : IDL.Opt(StreamingCallbackToken), 100 | 'body' : IDL.Vec(IDL.Nat8), 101 | }); 102 | const StreamingCallback = IDL.Func( 103 | [StreamingCallbackToken], 104 | [StreamingCallbackResponse], 105 | ['query'], 106 | ); 107 | const StreamingStrategy = IDL.Variant({ 108 | 'Callback' : IDL.Record({ 109 | 'token' : StreamingCallbackToken, 110 | 'callback' : StreamingCallback, 111 | }), 112 | }); 113 | const Response = IDL.Record({ 114 | 'body' : IDL.Vec(IDL.Nat8), 115 | 'headers' : IDL.Vec(HeaderField), 116 | 'streaming_strategy' : IDL.Opt(StreamingStrategy), 117 | 'status_code' : IDL.Nat16, 118 | }); 119 | const Value = IDL.Variant({ 120 | 'Int' : IDL.Int, 121 | 'Nat' : IDL.Nat, 122 | 'Empty' : IDL.Null, 123 | 'Bool' : IDL.Bool, 124 | 'Text' : IDL.Text, 125 | 'Float' : IDL.Float64, 126 | 'Principal' : IDL.Principal, 127 | 'Class' : IDL.Vec(Property), 128 | }); 129 | Property.fill( 130 | IDL.Record({ 'value' : Value, 'name' : IDL.Text, 'immutable' : IDL.Bool }) 131 | ); 132 | const Properties = IDL.Vec(Property); 133 | const Egg = IDL.Record({ 134 | 'contentType' : IDL.Text, 135 | 'owner' : IDL.Opt(IDL.Principal), 136 | 'properties' : Properties, 137 | 'isPrivate' : IDL.Bool, 138 | 'payload' : IDL.Variant({ 139 | 'StagedData' : IDL.Null, 140 | 'Payload' : IDL.Vec(IDL.Nat8), 141 | }), 142 | }); 143 | const Result_5 = IDL.Variant({ 'ok' : IDL.Principal, 'err' : Error }); 144 | Query.fill(IDL.Record({ 'name' : IDL.Text, 'next' : IDL.Vec(Query) })); 145 | const QueryMode = IDL.Variant({ 'All' : IDL.Null, 'Some' : IDL.Vec(Query) }); 146 | const QueryRequest = IDL.Record({ 'id' : IDL.Text, 'mode' : QueryMode }); 147 | const Result = IDL.Variant({ 'ok' : Properties, 'err' : Error }); 148 | const Chunk = IDL.Record({ 149 | 'data' : IDL.Vec(IDL.Nat8), 150 | 'totalPages' : IDL.Nat, 151 | 'nextPage' : IDL.Opt(IDL.Nat), 152 | }); 153 | const PayloadResult = IDL.Variant({ 154 | 'Complete' : IDL.Vec(IDL.Nat8), 155 | 'Chunk' : Chunk, 156 | }); 157 | const PublicToken = IDL.Record({ 158 | 'id' : IDL.Text, 159 | 'contentType' : IDL.Text, 160 | 'owner' : IDL.Principal, 161 | 'createdAt' : IDL.Int, 162 | 'properties' : Properties, 163 | 'payload' : PayloadResult, 164 | }); 165 | const Result_4 = IDL.Variant({ 'ok' : PublicToken, 'err' : Error }); 166 | const Result_3 = IDL.Variant({ 'ok' : Chunk, 'err' : Error }); 167 | const Metadata = IDL.Record({ 168 | 'id' : IDL.Text, 169 | 'contentType' : IDL.Text, 170 | 'owner' : IDL.Principal, 171 | 'createdAt' : IDL.Int, 172 | 'properties' : Properties, 173 | }); 174 | const Result_2 = IDL.Variant({ 'ok' : Metadata, 'err' : Error }); 175 | const UpdateEventCallback = IDL.Variant({ 176 | 'Set' : Callback__1, 177 | 'Remove' : IDL.Null, 178 | }); 179 | const UpdateMode = IDL.Variant({ 'Set' : Value, 'Next' : IDL.Vec(Update) }); 180 | Update.fill(IDL.Record({ 'mode' : UpdateMode, 'name' : IDL.Text })); 181 | const UpdateRequest = IDL.Record({ 182 | 'id' : IDL.Text, 183 | 'update' : IDL.Vec(Update), 184 | }); 185 | const Hub = IDL.Service({ 186 | 'assetRequest' : IDL.Func([AssetRequest], [], []), 187 | 'authorize' : IDL.Func([AuthorizeRequest], [Result_1], []), 188 | 'balanceOf' : IDL.Func([IDL.Principal], [IDL.Vec(IDL.Text)], []), 189 | 'getAuthorized' : IDL.Func([IDL.Text], [IDL.Vec(IDL.Principal)], ['query']), 190 | 'getContractInfo' : IDL.Func([], [ContractInfo], []), 191 | 'getEventCallbackStatus' : IDL.Func([], [CallbackStatus], []), 192 | 'getMetadata' : IDL.Func([], [ContractMetadata], ['query']), 193 | 'getTotalMinted' : IDL.Func([], [IDL.Nat], ['query']), 194 | 'http_request' : IDL.Func([Request], [Response], ['query']), 195 | 'http_request_streaming_callback' : IDL.Func( 196 | [StreamingCallbackToken], 197 | [StreamingCallbackResponse], 198 | ['query'], 199 | ), 200 | 'init' : IDL.Func([IDL.Vec(IDL.Principal), ContractMetadata], [], []), 201 | 'isAuthorized' : IDL.Func([IDL.Text, IDL.Principal], [IDL.Bool], ['query']), 202 | 'listAssets' : IDL.Func( 203 | [], 204 | [IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text, IDL.Nat))], 205 | ['query'], 206 | ), 207 | 'mint' : IDL.Func([Egg], [IDL.Text], []), 208 | 'nftStreamingCallback' : IDL.Func( 209 | [StreamingCallbackToken], 210 | [StreamingCallbackResponse], 211 | ['query'], 212 | ), 213 | 'ownerOf' : IDL.Func([IDL.Text], [Result_5], ['query']), 214 | 'queryProperties' : IDL.Func([QueryRequest], [Result], ['query']), 215 | 'staticStreamingCallback' : IDL.Func( 216 | [StreamingCallbackToken], 217 | [StreamingCallbackResponse], 218 | ['query'], 219 | ), 220 | 'tokenByIndex' : IDL.Func([IDL.Text], [Result_4], []), 221 | 'tokenChunkByIndex' : IDL.Func([IDL.Text, IDL.Nat], [Result_3], []), 222 | 'tokenMetadataByIndex' : IDL.Func([IDL.Text], [Result_2], []), 223 | 'transfer' : IDL.Func([IDL.Principal, IDL.Text], [Result_1], []), 224 | 'updateContractOwners' : IDL.Func( 225 | [IDL.Principal, IDL.Bool], 226 | [Result_1], 227 | [], 228 | ), 229 | 'updateEventCallback' : IDL.Func([UpdateEventCallback], [], []), 230 | 'updateProperties' : IDL.Func([UpdateRequest], [Result], []), 231 | 'wallet_receive' : IDL.Func([], [], []), 232 | 'writeStaged' : IDL.Func([StagedWrite], [], []), 233 | }); 234 | return Hub; 235 | }; 236 | export const init = ({ }) => { return []; }; 237 | -------------------------------------------------------------------------------- /src/idls/dip_20.did.ts: -------------------------------------------------------------------------------- 1 | export default ({ IDL }) => { 2 | const TxError = IDL.Variant({ 3 | 'InsufficientAllowance' : IDL.Null, 4 | 'InsufficientBalance' : IDL.Null, 5 | 'ErrorOperationStyle' : IDL.Null, 6 | 'Unauthorized' : IDL.Null, 7 | 'LedgerTrap' : IDL.Null, 8 | 'ErrorTo' : IDL.Null, 9 | 'Other' : IDL.Null, 10 | 'BlockUsed' : IDL.Null, 11 | 'AmountTooSmall' : IDL.Null, 12 | }); 13 | const Result = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : TxError }); 14 | const Metadata = IDL.Record({ 15 | 'fee' : IDL.Nat, 16 | 'decimals' : IDL.Nat8, 17 | 'owner' : IDL.Principal, 18 | 'logo' : IDL.Text, 19 | 'name' : IDL.Text, 20 | 'totalSupply' : IDL.Nat, 21 | 'symbol' : IDL.Text, 22 | }); 23 | const TokenInfo = IDL.Record({ 24 | 'holderNumber' : IDL.Nat64, 25 | 'deployTime' : IDL.Nat64, 26 | 'metadata' : Metadata, 27 | 'historySize' : IDL.Nat64, 28 | 'cycles' : IDL.Nat64, 29 | 'feeTo' : IDL.Principal, 30 | }); 31 | return IDL.Service({ 32 | 'allowance' : IDL.Func( 33 | [IDL.Principal, IDL.Principal], 34 | [IDL.Nat], 35 | ['query'], 36 | ), 37 | 'approve' : IDL.Func([IDL.Principal, IDL.Nat], [Result], []), 38 | 'balanceOf' : IDL.Func([IDL.Principal], [IDL.Nat], ['query']), 39 | 'decimals' : IDL.Func([], [IDL.Nat8], ['query']), 40 | 'getAllowanceSize' : IDL.Func([], [IDL.Nat64], ['query']), 41 | 'getBlockUsed' : IDL.Func([], [IDL.Vec(IDL.Nat64)], ['query']), 42 | 'getHolders' : IDL.Func( 43 | [IDL.Nat64, IDL.Nat64], 44 | [IDL.Vec(IDL.Tuple(IDL.Principal, IDL.Nat))], 45 | ['query'], 46 | ), 47 | 'getMetadata' : IDL.Func([], [Metadata], ['query']), 48 | 'getTokenInfo' : IDL.Func([], [TokenInfo], ['query']), 49 | 'getUserApprovals' : IDL.Func( 50 | [IDL.Principal], 51 | [IDL.Vec(IDL.Tuple(IDL.Principal, IDL.Nat))], 52 | ['query'], 53 | ), 54 | 'historySize' : IDL.Func([], [IDL.Nat64], ['query']), 55 | 'isBlockUsed' : IDL.Func([IDL.Nat64], [IDL.Bool], ['query']), 56 | 'logo' : IDL.Func([], [IDL.Text], ['query']), 57 | 'mint' : IDL.Func([IDL.Opt(IDL.Vec(IDL.Nat8)), IDL.Nat64], [Result], []), 58 | 'mintFor' : IDL.Func( 59 | [IDL.Opt(IDL.Vec(IDL.Nat8)), IDL.Nat64, IDL.Principal], 60 | [Result], 61 | [], 62 | ), 63 | 'name' : IDL.Func([], [IDL.Text], ['query']), 64 | 'owner' : IDL.Func([], [IDL.Principal], ['query']), 65 | 'setFee' : IDL.Func([IDL.Nat], [], []), 66 | 'setFeeTo' : IDL.Func([IDL.Principal], [], []), 67 | 'setGenesis' : IDL.Func([], [Result], []), 68 | 'setLogo' : IDL.Func([IDL.Text], [], []), 69 | 'setName' : IDL.Func([IDL.Text], [], []), 70 | 'setOwner' : IDL.Func([IDL.Principal], [], []), 71 | 'symbol' : IDL.Func([], [IDL.Text], ['query']), 72 | 'totalSupply' : IDL.Func([], [IDL.Nat], ['query']), 73 | 'transfer' : IDL.Func([IDL.Principal, IDL.Nat], [Result], []), 74 | 'transferFrom' : IDL.Func( 75 | [IDL.Principal, IDL.Principal, IDL.Nat], 76 | [Result], 77 | [], 78 | ), 79 | 'withdraw' : IDL.Func([IDL.Nat64, IDL.Text], [Result], []), 80 | }); 81 | }; 82 | export const init = ({ IDL }) => { 83 | return [ 84 | IDL.Text, 85 | IDL.Text, 86 | IDL.Text, 87 | IDL.Nat8, 88 | IDL.Nat, 89 | IDL.Principal, 90 | IDL.Nat, 91 | IDL.Principal, 92 | IDL.Principal, 93 | ]; 94 | }; 95 | -------------------------------------------------------------------------------- /src/idls/dip_721.did.ts: -------------------------------------------------------------------------------- 1 | export default ({ IDL }) => { 2 | const Vec = IDL.Rec(); 3 | const InitArgs = IDL.Record({ 4 | 'cap' : IDL.Opt(IDL.Principal), 5 | 'logo' : IDL.Opt(IDL.Text), 6 | 'name' : IDL.Opt(IDL.Text), 7 | 'custodians' : IDL.Opt(IDL.Vec(IDL.Principal)), 8 | 'symbol' : IDL.Opt(IDL.Text), 9 | }); 10 | const NftError = IDL.Variant({ 11 | 'UnauthorizedOperator' : IDL.Null, 12 | 'SelfTransfer' : IDL.Null, 13 | 'TokenNotFound' : IDL.Null, 14 | 'UnauthorizedOwner' : IDL.Null, 15 | 'SelfApprove' : IDL.Null, 16 | 'OperatorNotFound' : IDL.Null, 17 | 'ExistedNFT' : IDL.Null, 18 | 'OwnerNotFound' : IDL.Null, 19 | }); 20 | const Result = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : NftError }); 21 | const Result_1 = IDL.Variant({ 'Ok' : IDL.Bool, 'Err' : NftError }); 22 | const ManualReply = IDL.Record({ 23 | 'logo' : IDL.Opt(IDL.Text), 24 | 'name' : IDL.Opt(IDL.Text), 25 | 'created_at' : IDL.Nat64, 26 | 'upgraded_at' : IDL.Nat64, 27 | 'custodians' : IDL.Vec(IDL.Principal), 28 | 'symbol' : IDL.Opt(IDL.Text), 29 | }); 30 | Vec.fill( 31 | IDL.Vec( 32 | IDL.Tuple( 33 | IDL.Text, 34 | IDL.Variant({ 35 | 'Nat64Content' : IDL.Nat64, 36 | 'Nat32Content' : IDL.Nat32, 37 | 'BoolContent' : IDL.Bool, 38 | 'Nat8Content' : IDL.Nat8, 39 | 'Int64Content' : IDL.Int64, 40 | 'IntContent' : IDL.Int, 41 | 'NatContent' : IDL.Nat, 42 | 'Nat16Content' : IDL.Nat16, 43 | 'Int32Content' : IDL.Int32, 44 | 'Int8Content' : IDL.Int8, 45 | 'FloatContent' : IDL.Float64, 46 | 'Int16Content' : IDL.Int16, 47 | 'BlobContent' : IDL.Vec(IDL.Nat8), 48 | 'NestedContent' : Vec, 49 | 'Principal' : IDL.Principal, 50 | 'TextContent' : IDL.Text, 51 | }), 52 | ) 53 | ) 54 | ); 55 | const GenericValue = IDL.Variant({ 56 | 'Nat64Content' : IDL.Nat64, 57 | 'Nat32Content' : IDL.Nat32, 58 | 'BoolContent' : IDL.Bool, 59 | 'Nat8Content' : IDL.Nat8, 60 | 'Int64Content' : IDL.Int64, 61 | 'IntContent' : IDL.Int, 62 | 'NatContent' : IDL.Nat, 63 | 'Nat16Content' : IDL.Nat16, 64 | 'Int32Content' : IDL.Int32, 65 | 'Int8Content' : IDL.Int8, 66 | 'FloatContent' : IDL.Float64, 67 | 'Int16Content' : IDL.Int16, 68 | 'BlobContent' : IDL.Vec(IDL.Nat8), 69 | 'NestedContent' : Vec, 70 | 'Principal' : IDL.Principal, 71 | 'TextContent' : IDL.Text, 72 | }); 73 | const Result_2 = IDL.Variant({ 74 | 'Ok' : IDL.Opt(IDL.Principal), 75 | 'Err' : NftError, 76 | }); 77 | const ManualReply_1 = IDL.Variant({ 78 | 'Ok' : IDL.Vec(IDL.Nat), 79 | 'Err' : NftError, 80 | }); 81 | const TokenMetadata = IDL.Record({ 82 | 'transferred_at' : IDL.Opt(IDL.Nat64), 83 | 'transferred_by' : IDL.Opt(IDL.Principal), 84 | 'owner' : IDL.Opt(IDL.Principal), 85 | 'operator' : IDL.Opt(IDL.Principal), 86 | 'approved_at' : IDL.Opt(IDL.Nat64), 87 | 'approved_by' : IDL.Opt(IDL.Principal), 88 | 'properties' : IDL.Vec(IDL.Tuple(IDL.Text, GenericValue)), 89 | 'is_burned' : IDL.Bool, 90 | 'token_identifier' : IDL.Nat, 91 | 'burned_at' : IDL.Opt(IDL.Nat64), 92 | 'burned_by' : IDL.Opt(IDL.Principal), 93 | 'minted_at' : IDL.Nat64, 94 | 'minted_by' : IDL.Principal, 95 | }); 96 | const ManualReply_2 = IDL.Variant({ 97 | 'Ok' : IDL.Vec(TokenMetadata), 98 | 'Err' : NftError, 99 | }); 100 | const Stats = IDL.Record({ 101 | 'cycles' : IDL.Nat, 102 | 'total_transactions' : IDL.Nat, 103 | 'total_unique_holders' : IDL.Nat, 104 | 'total_supply' : IDL.Nat, 105 | }); 106 | const SupportedInterface = IDL.Variant({ 107 | 'Burn' : IDL.Null, 108 | 'Mint' : IDL.Null, 109 | 'Approval' : IDL.Null, 110 | }); 111 | const ManualReply_3 = IDL.Variant({ 'Ok' : TokenMetadata, 'Err' : NftError }); 112 | return IDL.Service({ 113 | 'approve' : IDL.Func([IDL.Principal, IDL.Nat], [Result], []), 114 | 'balanceOf' : IDL.Func([IDL.Principal], [Result], ['query']), 115 | 'burn' : IDL.Func([IDL.Nat], [Result], []), 116 | 'custodians' : IDL.Func([], [IDL.Vec(IDL.Principal)], ['query']), 117 | 'cycles' : IDL.Func([], [IDL.Nat], ['query']), 118 | 'dfx_info' : IDL.Func([], [IDL.Text], ['query']), 119 | 'dip721_approve' : IDL.Func([IDL.Principal, IDL.Nat], [Result], []), 120 | 'dip721_balance_of' : IDL.Func([IDL.Principal], [Result], ['query']), 121 | 'dip721_burn' : IDL.Func([IDL.Nat], [Result], []), 122 | 'dip721_custodians' : IDL.Func([], [IDL.Vec(IDL.Principal)], ['query']), 123 | 'dip721_cycles' : IDL.Func([], [IDL.Nat], ['query']), 124 | 'dip721_is_approved_for_all' : IDL.Func( 125 | [IDL.Principal, IDL.Principal], 126 | [Result_1], 127 | ['query'], 128 | ), 129 | 'dip721_logo' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), 130 | 'dip721_metadata' : IDL.Func([], [ManualReply], ['query']), 131 | 'dip721_mint' : IDL.Func( 132 | [IDL.Principal, IDL.Nat, IDL.Vec(IDL.Tuple(IDL.Text, GenericValue))], 133 | [Result], 134 | [], 135 | ), 136 | 'dip721_name' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), 137 | 'dip721_operator_of' : IDL.Func([IDL.Nat], [Result_2], ['query']), 138 | 'dip721_operator_token_identifiers' : IDL.Func( 139 | [IDL.Principal], 140 | [ManualReply_1], 141 | ['query'], 142 | ), 143 | 'dip721_operator_token_metadata' : IDL.Func( 144 | [IDL.Principal], 145 | [ManualReply_2], 146 | ['query'], 147 | ), 148 | 'dip721_owner_of' : IDL.Func([IDL.Nat], [Result_2], ['query']), 149 | 'dip721_owner_token_identifiers' : IDL.Func( 150 | [IDL.Principal], 151 | [ManualReply_1], 152 | ['query'], 153 | ), 154 | 'dip721_owner_token_metadata' : IDL.Func( 155 | [IDL.Principal], 156 | [ManualReply_2], 157 | ['query'], 158 | ), 159 | 'dip721_set_approval_for_all' : IDL.Func( 160 | [IDL.Principal, IDL.Bool], 161 | [Result], 162 | [], 163 | ), 164 | 'dip721_set_custodians' : IDL.Func([IDL.Vec(IDL.Principal)], [], []), 165 | 'dip721_set_logo' : IDL.Func([IDL.Text], [], []), 166 | 'dip721_set_name' : IDL.Func([IDL.Text], [], []), 167 | 'dip721_set_symbol' : IDL.Func([IDL.Text], [], []), 168 | 'dip721_stats' : IDL.Func([], [Stats], ['query']), 169 | 'dip721_supported_interfaces' : IDL.Func( 170 | [], 171 | [IDL.Vec(SupportedInterface)], 172 | ['query'], 173 | ), 174 | 'dip721_symbol' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), 175 | 'dip721_token_metadata' : IDL.Func([IDL.Nat], [ManualReply_3], ['query']), 176 | 'dip721_total_supply' : IDL.Func([], [IDL.Nat], ['query']), 177 | 'dip721_total_transactions' : IDL.Func([], [IDL.Nat], ['query']), 178 | 'dip721_total_unique_holders' : IDL.Func([], [IDL.Nat], ['query']), 179 | 'dip721_transfer' : IDL.Func([IDL.Principal, IDL.Nat], [Result], []), 180 | 'dip721_transfer_from' : IDL.Func( 181 | [IDL.Principal, IDL.Principal, IDL.Nat], 182 | [Result], 183 | [], 184 | ), 185 | 'git_commit_hash' : IDL.Func([], [IDL.Text], ['query']), 186 | 'isApprovedForAll' : IDL.Func( 187 | [IDL.Principal, IDL.Principal], 188 | [Result_1], 189 | ['query'], 190 | ), 191 | 'logo' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), 192 | 'metadata' : IDL.Func([], [ManualReply], ['query']), 193 | 'mint' : IDL.Func( 194 | [IDL.Principal, IDL.Nat, IDL.Vec(IDL.Tuple(IDL.Text, GenericValue))], 195 | [Result], 196 | [], 197 | ), 198 | 'name' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), 199 | 'operatorOf' : IDL.Func([IDL.Nat], [Result_2], ['query']), 200 | 'operatorTokenIdentifiers' : IDL.Func( 201 | [IDL.Principal], 202 | [ManualReply_1], 203 | ['query'], 204 | ), 205 | 'operatorTokenMetadata' : IDL.Func( 206 | [IDL.Principal], 207 | [ManualReply_2], 208 | ['query'], 209 | ), 210 | 'ownerOf' : IDL.Func([IDL.Nat], [Result_2], ['query']), 211 | 'ownerTokenIdentifiers' : IDL.Func( 212 | [IDL.Principal], 213 | [ManualReply_1], 214 | ['query'], 215 | ), 216 | 'ownerTokenMetadata' : IDL.Func( 217 | [IDL.Principal], 218 | [ManualReply_2], 219 | ['query'], 220 | ), 221 | 'rust_toolchain_info' : IDL.Func([], [IDL.Text], ['query']), 222 | 'setApprovalForAll' : IDL.Func([IDL.Principal, IDL.Bool], [Result], []), 223 | 'setCustodians' : IDL.Func([IDL.Vec(IDL.Principal)], [], []), 224 | 'setLogo' : IDL.Func([IDL.Text], [], []), 225 | 'setName' : IDL.Func([IDL.Text], [], []), 226 | 'setSymbol' : IDL.Func([IDL.Text], [], []), 227 | 'stats' : IDL.Func([], [Stats], ['query']), 228 | 'supportedInterfaces' : IDL.Func( 229 | [], 230 | [IDL.Vec(SupportedInterface)], 231 | ['query'], 232 | ), 233 | 'symbol' : IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), 234 | 'tokenMetadata' : IDL.Func([IDL.Nat], [ManualReply_3], ['query']), 235 | 'totalSupply' : IDL.Func([], [IDL.Nat], ['query']), 236 | 'totalTransactions' : IDL.Func([], [IDL.Nat], ['query']), 237 | 'totalUniqueHolders' : IDL.Func([], [IDL.Nat], ['query']), 238 | 'transfer' : IDL.Func([IDL.Principal, IDL.Nat], [Result], []), 239 | 'transferFrom' : IDL.Func( 240 | [IDL.Principal, IDL.Principal, IDL.Nat], 241 | [Result], 242 | [], 243 | ), 244 | }); 245 | }; 246 | -------------------------------------------------------------------------------- /src/idls/drc_20.did.ts: -------------------------------------------------------------------------------- 1 | export default ({ IDL }) => { 2 | const Metadata = IDL.Record({ content: IDL.Text, name: IDL.Text }); 3 | const Address = IDL.Text; 4 | const InitArgs = IDL.Record({ 5 | fee: IDL.Nat, 6 | decimals: IDL.Nat8, 7 | metadata: IDL.Opt(IDL.Vec(Metadata)), 8 | name: IDL.Opt(IDL.Text), 9 | totalSupply: IDL.Nat, 10 | founder: IDL.Opt(Address), 11 | symbol: IDL.Opt(IDL.Text), 12 | }); 13 | const Spender = IDL.Text; 14 | const Amount = IDL.Nat; 15 | const AccountId = IDL.Vec(IDL.Nat8); 16 | const Allowance = IDL.Record({ 17 | remaining: IDL.Nat, 18 | spender: AccountId, 19 | }); 20 | const Nonce = IDL.Nat; 21 | const Sa = IDL.Vec(IDL.Nat8); 22 | const Data = IDL.Vec(IDL.Nat8); 23 | const Txid = IDL.Vec(IDL.Nat8); 24 | const TxnResult = IDL.Variant({ 25 | ok: Txid, 26 | err: IDL.Record({ 27 | code: IDL.Variant({ 28 | NonceError: IDL.Null, 29 | InsufficientGas: IDL.Null, 30 | InsufficientAllowance: IDL.Null, 31 | UndefinedError: IDL.Null, 32 | InsufficientBalance: IDL.Null, 33 | NoLockedTransfer: IDL.Null, 34 | DuplicateExecutedTransfer: IDL.Null, 35 | LockedTransferExpired: IDL.Null, 36 | }), 37 | message: IDL.Text, 38 | }), 39 | }); 40 | const ExecuteType = IDL.Variant({ 41 | fallback: IDL.Null, 42 | send: IDL.Nat, 43 | sendAll: IDL.Null, 44 | }); 45 | const To = IDL.Text; 46 | const CoinSeconds = IDL.Record({ 47 | updateTime: IDL.Int, 48 | coinSeconds: IDL.Nat, 49 | }); 50 | const Timeout = IDL.Nat32; 51 | const Decider = IDL.Text; 52 | const From = IDL.Text; 53 | const Gas = IDL.Variant({ 54 | token: IDL.Nat, 55 | cycles: IDL.Nat, 56 | noFee: IDL.Null, 57 | }); 58 | const Time = IDL.Int; 59 | const Operation = IDL.Variant({ 60 | approve: IDL.Record({ allowance: IDL.Nat }), 61 | lockTransfer: IDL.Record({ 62 | locked: IDL.Nat, 63 | expiration: Time, 64 | decider: AccountId, 65 | }), 66 | transfer: IDL.Record({ 67 | action: IDL.Variant({ 68 | burn: IDL.Null, 69 | mint: IDL.Null, 70 | send: IDL.Null, 71 | }), 72 | }), 73 | executeTransfer: IDL.Record({ 74 | fallback: IDL.Nat, 75 | lockedTxid: Txid, 76 | }), 77 | }); 78 | const Transaction = IDL.Record({ 79 | to: AccountId, 80 | value: IDL.Nat, 81 | data: IDL.Opt(IDL.Vec(IDL.Nat8)), 82 | from: AccountId, 83 | operation: Operation, 84 | }); 85 | const TxnRecord = IDL.Record({ 86 | gas: Gas, 87 | msgCaller: IDL.Opt(IDL.Principal), 88 | transaction: Transaction, 89 | txid: Txid, 90 | nonce: IDL.Nat, 91 | timestamp: Time, 92 | caller: AccountId, 93 | index: IDL.Nat, 94 | }); 95 | const Callback = IDL.Func([TxnRecord], [], []); 96 | const MsgType = IDL.Variant({ 97 | onApprove: IDL.Null, 98 | onExecute: IDL.Null, 99 | onTransfer: IDL.Null, 100 | onLock: IDL.Null, 101 | }); 102 | const Subscription = IDL.Record({ 103 | callback: Callback, 104 | msgTypes: IDL.Vec(MsgType), 105 | }); 106 | const TxnQueryRequest = IDL.Variant({ 107 | getEvents: IDL.Record({ owner: IDL.Opt(Address) }), 108 | txnCount: IDL.Record({ owner: Address }), 109 | lockedTxns: IDL.Record({ owner: Address }), 110 | lastTxids: IDL.Record({ owner: Address }), 111 | lastTxidsGlobal: IDL.Null, 112 | getTxn: IDL.Record({ txid: Txid }), 113 | txnCountGlobal: IDL.Null, 114 | }); 115 | const TxnQueryResponse = IDL.Variant({ 116 | getEvents: IDL.Vec(TxnRecord), 117 | txnCount: IDL.Nat, 118 | lockedTxns: IDL.Record({ 119 | txns: IDL.Vec(TxnRecord), 120 | lockedBalance: IDL.Nat, 121 | }), 122 | lastTxids: IDL.Vec(Txid), 123 | lastTxidsGlobal: IDL.Vec(Txid), 124 | getTxn: IDL.Opt(TxnRecord), 125 | txnCountGlobal: IDL.Nat, 126 | }); 127 | const DRC20 = IDL.Service({ 128 | drc20_allowance: IDL.Func([Address, Spender], [Amount], ['query']), 129 | drc20_approvals: IDL.Func([Address], [IDL.Vec(Allowance)], ['query']), 130 | drc20_approve: IDL.Func( 131 | [Spender, Amount, IDL.Opt(Nonce), IDL.Opt(Sa), IDL.Opt(Data)], 132 | [TxnResult], 133 | [] 134 | ), 135 | drc20_balanceOf: IDL.Func([Address], [Amount], ['query']), 136 | drc20_decimals: IDL.Func([], [IDL.Nat8], ['query']), 137 | drc20_dropAccount: IDL.Func([IDL.Opt(Sa)], [IDL.Bool], []), 138 | drc20_executeTransfer: IDL.Func( 139 | [ 140 | Txid, 141 | ExecuteType, 142 | IDL.Opt(To), 143 | IDL.Opt(Nonce), 144 | IDL.Opt(Sa), 145 | IDL.Opt(Data), 146 | ], 147 | [TxnResult], 148 | [] 149 | ), 150 | drc20_fee: IDL.Func([], [Amount], ['query']), 151 | drc20_getCoinSeconds: IDL.Func( 152 | [IDL.Opt(Address)], 153 | [CoinSeconds, IDL.Opt(CoinSeconds)], 154 | ['query'] 155 | ), 156 | drc20_holdersCount: IDL.Func([], [IDL.Nat, IDL.Nat, IDL.Nat], ['query']), 157 | drc20_lockTransfer: IDL.Func( 158 | [ 159 | To, 160 | Amount, 161 | Timeout, 162 | IDL.Opt(Decider), 163 | IDL.Opt(Nonce), 164 | IDL.Opt(Sa), 165 | IDL.Opt(Data), 166 | ], 167 | [TxnResult], 168 | [] 169 | ), 170 | drc20_lockTransferFrom: IDL.Func( 171 | [ 172 | From, 173 | To, 174 | Amount, 175 | Timeout, 176 | IDL.Opt(Decider), 177 | IDL.Opt(Nonce), 178 | IDL.Opt(Sa), 179 | IDL.Opt(Data), 180 | ], 181 | [TxnResult], 182 | [] 183 | ), 184 | drc20_metadata: IDL.Func([], [IDL.Vec(Metadata)], ['query']), 185 | drc20_name: IDL.Func([], [IDL.Text], ['query']), 186 | drc20_subscribe: IDL.Func( 187 | [Callback, IDL.Vec(MsgType), IDL.Opt(Sa)], 188 | [IDL.Bool], 189 | [] 190 | ), 191 | drc20_subscribed: IDL.Func([Address], [IDL.Opt(Subscription)], ['query']), 192 | drc20_symbol: IDL.Func([], [IDL.Text], ['query']), 193 | drc20_totalSupply: IDL.Func([], [Amount], ['query']), 194 | drc20_transfer: IDL.Func( 195 | [To, Amount, IDL.Opt(Nonce), IDL.Opt(Sa), IDL.Opt(Data)], 196 | [TxnResult], 197 | [] 198 | ), 199 | drc20_transferBatch: IDL.Func( 200 | [ 201 | IDL.Vec(To), 202 | IDL.Vec(Amount), 203 | IDL.Opt(Nonce), 204 | IDL.Opt(Sa), 205 | IDL.Opt(Data), 206 | ], 207 | [IDL.Vec(TxnResult)], 208 | [] 209 | ), 210 | drc20_transferFrom: IDL.Func( 211 | [From, To, Amount, IDL.Opt(Nonce), IDL.Opt(Sa), IDL.Opt(Data)], 212 | [TxnResult], 213 | [] 214 | ), 215 | drc20_txnQuery: IDL.Func([TxnQueryRequest], [TxnQueryResponse], ['query']), 216 | drc20_txnRecord: IDL.Func([Txid], [IDL.Opt(TxnRecord)], []), 217 | standard: IDL.Func([], [IDL.Text], ['query']), 218 | }); 219 | return DRC20; 220 | }; 221 | export const init = ({ IDL }) => { 222 | const Metadata = IDL.Record({ content: IDL.Text, name: IDL.Text }); 223 | const Address = IDL.Text; 224 | const InitArgs = IDL.Record({ 225 | fee: IDL.Nat, 226 | decimals: IDL.Nat8, 227 | metadata: IDL.Opt(IDL.Vec(Metadata)), 228 | name: IDL.Opt(IDL.Text), 229 | totalSupply: IDL.Nat, 230 | founder: IDL.Opt(Address), 231 | symbol: IDL.Opt(IDL.Text), 232 | }); 233 | return [InitArgs]; 234 | }; 235 | -------------------------------------------------------------------------------- /src/idls/ext.did.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/camelcase */ 2 | /* eslint-disable camelcase */ 3 | export default ({ IDL }) => { 4 | const TokenIndex = IDL.Nat32; 5 | const AccountIdentifier = IDL.Text; 6 | const TokenIdentifier = IDL.Text; 7 | const Balance = IDL.Nat; 8 | const Time = IDL.Int; 9 | const SubAccount = IDL.Vec(IDL.Nat8); 10 | const Memo = IDL.Vec(IDL.Nat8); 11 | const Listing = IDL.Record({ 12 | locked: IDL.Opt(Time), 13 | seller: IDL.Principal, 14 | price: IDL.Nat64, 15 | }); 16 | const User = IDL.Variant({ 17 | principal: IDL.Principal, 18 | address: AccountIdentifier, 19 | }); 20 | const CommonError = IDL.Variant({ 21 | InvalidToken: TokenIdentifier, 22 | Other: IDL.Text, 23 | }); 24 | 25 | const BalanceRequest = IDL.Record({ 26 | token: TokenIdentifier, 27 | user: User, 28 | }); 29 | const BalanceResult = IDL.Variant({ ok: Balance, err: CommonError }); 30 | 31 | const DetailsResult = IDL.Variant({ 32 | ok: IDL.Tuple(AccountIdentifier, IDL.Opt(Listing)), 33 | err: CommonError, 34 | }); 35 | 36 | const TokensResult = IDL.Variant({ 37 | ok: IDL.Vec(TokenIndex), 38 | err: CommonError, 39 | }); 40 | const TokenExtResult = IDL.Variant({ 41 | ok: IDL.Vec( 42 | IDL.Tuple(TokenIndex, IDL.Opt(Listing), IDL.Opt(IDL.Vec(IDL.Nat8))) 43 | ), 44 | err: CommonError, 45 | }); 46 | 47 | const TransferRequest = IDL.Record({ 48 | to: User, 49 | token: TokenIdentifier, 50 | notify: IDL.Bool, 51 | from: User, 52 | memo: Memo, 53 | subaccount: IDL.Opt(SubAccount), 54 | amount: Balance, 55 | fee: IDL.Nat, 56 | }); 57 | const TransferResult = IDL.Variant({ 58 | ok: Balance, 59 | err: IDL.Variant({ 60 | CannotNotify: AccountIdentifier, 61 | InsufficientBalance: IDL.Null, 62 | InvalidToken: TokenIdentifier, 63 | Rejected: IDL.Null, 64 | Unauthorized: AccountIdentifier, 65 | Other: IDL.Text, 66 | }), 67 | }); 68 | const Metadata = IDL.Variant({ 69 | fungible: IDL.Record({ 70 | decimals: IDL.Nat8, 71 | metadata: IDL.Opt(IDL.Vec(IDL.Nat8)), 72 | name: IDL.Text, 73 | symbol: IDL.Text, 74 | }), 75 | nonfungible: IDL.Record({ metadata: IDL.Opt(IDL.Vec(IDL.Nat8)) }), 76 | }); 77 | const MetadataResult = IDL.Variant({ ok: Metadata, err: CommonError }); 78 | const SupplyResult = IDL.Variant({ ok: Balance, err: CommonError }); 79 | return IDL.Service({ 80 | extensions: IDL.Func([], [IDL.Vec(IDL.Text)], ['query']), 81 | balance: IDL.Func([BalanceRequest], [BalanceResult], ['query']), 82 | details: IDL.Func([TokenIdentifier], [DetailsResult], ['query']), 83 | tokens: IDL.Func([AccountIdentifier], [TokensResult], ['query']), 84 | tokens_ext: IDL.Func([AccountIdentifier], [TokenExtResult], ['query']), 85 | transfer: IDL.Func([TransferRequest], [TransferResult], []), 86 | metadata: IDL.Func([TokenIdentifier], [MetadataResult], ['query']), 87 | supply: IDL.Func([TokenIdentifier], [SupplyResult], ['query']), 88 | }); 89 | }; 90 | export const init = () => { 91 | return []; 92 | }; 93 | -------------------------------------------------------------------------------- /src/idls/icpunks.did.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable camelcase */ 2 | /* eslint-disable @typescript-eslint/camelcase */ 3 | export default ({ IDL }) => { 4 | const Property = IDL.Record({ value: IDL.Text, name: IDL.Text }); 5 | const TokenDesc = IDL.Record({ 6 | id: IDL.Nat, 7 | url: IDL.Text, 8 | owner: IDL.Principal, 9 | desc: IDL.Text, 10 | name: IDL.Text, 11 | properties: IDL.Vec(Property), 12 | }); 13 | const TokenIndex = IDL.Nat; 14 | 15 | const ICPunk = IDL.Service({ 16 | data_of: IDL.Func([TokenIndex], [TokenDesc], []), 17 | transfer_to: IDL.Func([IDL.Principal, TokenIndex], [IDL.Bool], []), 18 | user_tokens: IDL.Func([IDL.Principal], [IDL.Vec(IDL.Nat)], []), 19 | }); 20 | return ICPunk; 21 | }; 22 | export const init = ({ IDL }) => { 23 | return [IDL.Text, IDL.Text, IDL.Nat, IDL.Principal]; 24 | }; 25 | -------------------------------------------------------------------------------- /src/idls/icrc_1.did.ts: -------------------------------------------------------------------------------- 1 | export default ({ IDL }) => { 2 | const GetTransactionsRequest = IDL.Record({ 3 | 'start' : IDL.Nat, 4 | 'length' : IDL.Nat, 5 | }); 6 | const Account = IDL.Record({ 7 | 'owner' : IDL.Principal, 8 | 'subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)), 9 | }); 10 | const Burn = IDL.Record({ 11 | 'from' : Account, 12 | 'memo' : IDL.Opt(IDL.Vec(IDL.Nat8)), 13 | 'created_at_time' : IDL.Opt(IDL.Nat64), 14 | 'amount' : IDL.Nat, 15 | }); 16 | const Mint = IDL.Record({ 17 | 'to' : Account, 18 | 'memo' : IDL.Opt(IDL.Vec(IDL.Nat8)), 19 | 'created_at_time' : IDL.Opt(IDL.Nat64), 20 | 'amount' : IDL.Nat, 21 | }); 22 | const Transfer = IDL.Record({ 23 | 'to' : Account, 24 | 'fee' : IDL.Opt(IDL.Nat), 25 | 'from' : Account, 26 | 'memo' : IDL.Opt(IDL.Vec(IDL.Nat8)), 27 | 'created_at_time' : IDL.Opt(IDL.Nat64), 28 | 'amount' : IDL.Nat, 29 | }); 30 | const Transaction = IDL.Record({ 31 | 'burn' : IDL.Opt(Burn), 32 | 'kind' : IDL.Text, 33 | 'mint' : IDL.Opt(Mint), 34 | 'timestamp' : IDL.Nat64, 35 | 'transfer' : IDL.Opt(Transfer), 36 | }); 37 | const ArchivedTransactionRange = IDL.Record({ 38 | 'callback' : IDL.Func( 39 | [GetTransactionsRequest], 40 | [IDL.Record({ 'transactions' : IDL.Vec(Transaction) })], 41 | ['query'], 42 | ), 43 | 'start' : IDL.Nat, 44 | 'length' : IDL.Nat, 45 | }); 46 | const GetTransactionsResponse = IDL.Record({ 47 | 'first_index' : IDL.Nat, 48 | 'log_length' : IDL.Nat, 49 | 'transactions' : IDL.Vec(Transaction), 50 | 'archived_transactions' : IDL.Vec(ArchivedTransactionRange), 51 | }); 52 | const HttpRequest = IDL.Record({ 53 | 'url' : IDL.Text, 54 | 'method' : IDL.Text, 55 | 'body' : IDL.Vec(IDL.Nat8), 56 | 'headers' : IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), 57 | }); 58 | const HttpResponse = IDL.Record({ 59 | 'body' : IDL.Vec(IDL.Nat8), 60 | 'headers' : IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), 61 | 'status_code' : IDL.Nat16, 62 | }); 63 | const Value = IDL.Variant({ 64 | 'Int' : IDL.Int, 65 | 'Nat' : IDL.Nat, 66 | 'Blob' : IDL.Vec(IDL.Nat8), 67 | 'Text' : IDL.Text, 68 | }); 69 | const StandardRecord = IDL.Record({ 'url' : IDL.Text, 'name' : IDL.Text }); 70 | const TransferArg = IDL.Record({ 71 | 'to' : Account, 72 | 'fee' : IDL.Opt(IDL.Nat), 73 | 'memo' : IDL.Opt(IDL.Vec(IDL.Nat8)), 74 | 'from_subaccount' : IDL.Opt(IDL.Vec(IDL.Nat8)), 75 | 'created_at_time' : IDL.Opt(IDL.Nat64), 76 | 'amount' : IDL.Nat, 77 | }); 78 | const TransferError = IDL.Variant({ 79 | 'GenericError' : IDL.Record({ 80 | 'message' : IDL.Text, 81 | 'error_code' : IDL.Nat, 82 | }), 83 | 'TemporarilyUnavailable' : IDL.Null, 84 | 'BadBurn' : IDL.Record({ 'min_burn_amount' : IDL.Nat }), 85 | 'Duplicate' : IDL.Record({ 'duplicate_of' : IDL.Nat }), 86 | 'BadFee' : IDL.Record({ 'expected_fee' : IDL.Nat }), 87 | 'CreatedInFuture' : IDL.Record({ 'ledger_time' : IDL.Nat64 }), 88 | 'TooOld' : IDL.Null, 89 | 'InsufficientFunds' : IDL.Record({ 'balance' : IDL.Nat }), 90 | }); 91 | const Result = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : TransferError }); 92 | return IDL.Service({ 93 | 'get_transactions' : IDL.Func( 94 | [GetTransactionsRequest], 95 | [GetTransactionsResponse], 96 | ['query'], 97 | ), 98 | 'http_request' : IDL.Func([HttpRequest], [HttpResponse], ['query']), 99 | 'icrc1_balance_of' : IDL.Func([Account], [IDL.Nat], ['query']), 100 | 'icrc1_decimals' : IDL.Func([], [IDL.Nat8], ['query']), 101 | 'icrc1_fee' : IDL.Func([], [IDL.Nat], ['query']), 102 | 'icrc1_metadata' : IDL.Func( 103 | [], 104 | [IDL.Vec(IDL.Tuple(IDL.Text, Value))], 105 | ['query'], 106 | ), 107 | 'icrc1_minting_account' : IDL.Func([], [IDL.Opt(Account)], ['query']), 108 | 'icrc1_name' : IDL.Func([], [IDL.Text], ['query']), 109 | 'icrc1_supported_standards' : IDL.Func( 110 | [], 111 | [IDL.Vec(StandardRecord)], 112 | ['query'], 113 | ), 114 | 'icrc1_symbol' : IDL.Func([], [IDL.Text], ['query']), 115 | 'icrc1_total_supply' : IDL.Func([], [IDL.Nat], ['query']), 116 | 'icrc1_transfer' : IDL.Func([TransferArg], [Result], []), 117 | }); 118 | }; 119 | export const init = () => { return []; }; 120 | -------------------------------------------------------------------------------- /src/idls/icrc_7.did.ts: -------------------------------------------------------------------------------- 1 | export const idlFactory = ({ IDL }) => { 2 | const Value = IDL.Rec(); 3 | const Subaccount = IDL.Vec(IDL.Nat8); 4 | const Account = IDL.Record({ 5 | owner: IDL.Principal, 6 | subaccount: IDL.Opt(Subaccount), 7 | }); 8 | Value.fill( 9 | IDL.Variant({ 10 | Int: IDL.Int, 11 | Map: IDL.Vec(IDL.Tuple(IDL.Text, Value)), 12 | Nat: IDL.Nat, 13 | Blob: IDL.Vec(IDL.Nat8), 14 | Text: IDL.Text, 15 | Array: IDL.Vec(Value), 16 | }) 17 | ); 18 | const TransferArg = IDL.Record({ 19 | to: Account, 20 | token_id: IDL.Nat, 21 | memo: IDL.Opt(IDL.Vec(IDL.Nat8)), 22 | from_subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)), 23 | created_at_time: IDL.Opt(IDL.Nat64), 24 | }); 25 | const TransferError = IDL.Variant({ 26 | GenericError: IDL.Record({ 27 | message: IDL.Text, 28 | error_code: IDL.Nat, 29 | }), 30 | Duplicate: IDL.Record({ duplicate_of: IDL.Nat }), 31 | NonExistingTokenId: IDL.Null, 32 | Unauthorized: IDL.Null, 33 | CreatedInFuture: IDL.Record({ ledger_time: IDL.Nat64 }), 34 | InvalidRecipient: IDL.Null, 35 | GenericBatchError: IDL.Record({ 36 | message: IDL.Text, 37 | error_code: IDL.Nat, 38 | }), 39 | TooOld: IDL.Null, 40 | }); 41 | const TransferResult = IDL.Variant({ Ok: IDL.Nat, Err: TransferError }); 42 | return IDL.Service({ 43 | icrc7_atomic_batch_transfers: IDL.Func([], [IDL.Opt(IDL.Bool)], ['query']), 44 | icrc7_balance_of: IDL.Func( 45 | [IDL.Vec(Account)], 46 | [IDL.Vec(IDL.Nat)], 47 | ['query'] 48 | ), 49 | icrc7_collection_metadata: IDL.Func( 50 | [], 51 | [IDL.Vec(IDL.Tuple(IDL.Text, Value))], 52 | ['query'] 53 | ), 54 | icrc7_default_take_value: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), 55 | icrc7_description: IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), 56 | icrc7_logo: IDL.Func([], [IDL.Opt(IDL.Text)], ['query']), 57 | icrc7_max_memo_size: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), 58 | icrc7_max_query_batch_size: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), 59 | icrc7_max_take_value: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), 60 | icrc7_max_update_batch_size: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), 61 | icrc7_name: IDL.Func([], [IDL.Text], ['query']), 62 | icrc7_owner_of: IDL.Func( 63 | [IDL.Vec(IDL.Nat)], 64 | [IDL.Vec(IDL.Opt(Account))], 65 | ['query'] 66 | ), 67 | icrc7_permitted_drift: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), 68 | icrc7_supply_cap: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), 69 | icrc7_symbol: IDL.Func([], [IDL.Text], ['query']), 70 | icrc7_token_metadata: IDL.Func( 71 | [IDL.Vec(IDL.Nat)], 72 | [IDL.Vec(IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, Value))))], 73 | ['query'] 74 | ), 75 | icrc7_tokens: IDL.Func( 76 | [IDL.Opt(IDL.Nat), IDL.Opt(IDL.Nat)], 77 | [IDL.Vec(IDL.Nat)], 78 | ['query'] 79 | ), 80 | icrc7_tokens_of: IDL.Func( 81 | [Account, IDL.Opt(IDL.Nat), IDL.Opt(IDL.Nat)], 82 | [IDL.Vec(IDL.Nat)], 83 | ['query'] 84 | ), 85 | icrc7_total_supply: IDL.Func([], [IDL.Nat], ['query']), 86 | icrc7_transfer: IDL.Func( 87 | [IDL.Vec(TransferArg)], 88 | [IDL.Vec(IDL.Opt(TransferResult))], 89 | [] 90 | ), 91 | icrc7_tx_window: IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']), 92 | }); 93 | }; 94 | -------------------------------------------------------------------------------- /src/idls/ledger.did.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/class-name-casing */ 2 | /* eslint-disable camelcase */ 3 | /* eslint-disable @typescript-eslint/camelcase */ 4 | export default ({ IDL }) => { 5 | const AccountIdentifier = IDL.Text; 6 | const Duration = IDL.Record({ secs: IDL.Nat64, nanos: IDL.Nat32 }); 7 | const ArchiveOptions = IDL.Record({ 8 | max_message_size_bytes: IDL.Opt(IDL.Nat32), 9 | node_max_memory_size_bytes: IDL.Opt(IDL.Nat32), 10 | controller_id: IDL.Principal, 11 | }); 12 | const ICPTs = IDL.Record({ e8s: IDL.Nat64 }); 13 | const LedgerCanisterInitPayload = IDL.Record({ 14 | send_whitelist: IDL.Vec(IDL.Tuple(IDL.Principal)), 15 | minting_account: AccountIdentifier, 16 | transaction_window: IDL.Opt(Duration), 17 | max_message_size_bytes: IDL.Opt(IDL.Nat32), 18 | archive_options: IDL.Opt(ArchiveOptions), 19 | initial_values: IDL.Vec(IDL.Tuple(AccountIdentifier, ICPTs)), 20 | }); 21 | const AccountBalanceArgs = IDL.Record({ account: AccountIdentifier }); 22 | const SubAccount = IDL.Vec(IDL.Nat8); 23 | const BlockHeight = IDL.Nat64; 24 | const NotifyCanisterArgs = IDL.Record({ 25 | to_subaccount: IDL.Opt(SubAccount), 26 | from_subaccount: IDL.Opt(SubAccount), 27 | to_canister: IDL.Principal, 28 | max_fee: ICPTs, 29 | block_height: BlockHeight, 30 | }); 31 | const Memo = IDL.Nat64; 32 | const TimeStamp = IDL.Record({ timestamp_nanos: IDL.Nat64 }); 33 | const SendArgs = IDL.Record({ 34 | to: AccountIdentifier, 35 | fee: ICPTs, 36 | memo: Memo, 37 | from_subaccount: IDL.Opt(SubAccount), 38 | created_at_time: IDL.Opt(TimeStamp), 39 | amount: ICPTs, 40 | }); 41 | return IDL.Service({ 42 | account_balance_dfx: IDL.Func([AccountBalanceArgs], [ICPTs], ['query']), 43 | notify_dfx: IDL.Func([NotifyCanisterArgs], [], []), 44 | send_dfx: IDL.Func([SendArgs], [BlockHeight], []), 45 | }); 46 | }; 47 | export const init = ({ IDL }) => { 48 | const AccountIdentifier = IDL.Text; 49 | const Duration = IDL.Record({ secs: IDL.Nat64, nanos: IDL.Nat32 }); 50 | const ArchiveOptions = IDL.Record({ 51 | max_message_size_bytes: IDL.Opt(IDL.Nat32), 52 | node_max_memory_size_bytes: IDL.Opt(IDL.Nat32), 53 | controller_id: IDL.Principal, 54 | }); 55 | const ICPTs = IDL.Record({ e8s: IDL.Nat64 }); 56 | const LedgerCanisterInitPayload = IDL.Record({ 57 | send_whitelist: IDL.Vec(IDL.Tuple(IDL.Principal)), 58 | minting_account: AccountIdentifier, 59 | transaction_window: IDL.Opt(Duration), 60 | max_message_size_bytes: IDL.Opt(IDL.Nat32), 61 | archive_options: IDL.Opt(ArchiveOptions), 62 | initial_values: IDL.Vec(IDL.Tuple(AccountIdentifier, ICPTs)), 63 | }); 64 | return [LedgerCanisterInitPayload]; 65 | }; 66 | -------------------------------------------------------------------------------- /src/idls/wicp.did.ts: -------------------------------------------------------------------------------- 1 | export default ({ IDL }) => { 2 | const TxError = IDL.Variant({ 3 | 'InsufficientAllowance' : IDL.Null, 4 | 'InsufficientBalance' : IDL.Null, 5 | 'ErrorOperationStyle' : IDL.Null, 6 | 'Unauthorized' : IDL.Null, 7 | 'LedgerTrap' : IDL.Null, 8 | 'ErrorTo' : IDL.Null, 9 | 'Other' : IDL.Null, 10 | 'BlockUsed' : IDL.Null, 11 | 'AmountTooSmall' : IDL.Null, 12 | }); 13 | const TxReceipt = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : TxError }); 14 | const Metadata = IDL.Record({ 15 | 'fee' : IDL.Nat, 16 | 'decimals' : IDL.Nat8, 17 | 'owner' : IDL.Principal, 18 | 'logo' : IDL.Text, 19 | 'name' : IDL.Text, 20 | 'totalSupply' : IDL.Nat, 21 | 'symbol' : IDL.Text, 22 | }); 23 | const TokenInfo = IDL.Record({ 24 | 'holderNumber' : IDL.Nat64, 25 | 'deployTime' : IDL.Nat64, 26 | 'metadata' : Metadata, 27 | 'historySize' : IDL.Nat64, 28 | 'cycles' : IDL.Nat64, 29 | 'feeTo' : IDL.Principal, 30 | }); 31 | return IDL.Service({ 32 | 'allowance' : IDL.Func( 33 | [IDL.Principal, IDL.Principal], 34 | [IDL.Nat], 35 | ['query'], 36 | ), 37 | 'approve' : IDL.Func([IDL.Principal, IDL.Nat], [TxReceipt], []), 38 | 'balanceOf' : IDL.Func([IDL.Principal], [IDL.Nat], ['query']), 39 | 'decimals' : IDL.Func([], [IDL.Nat8], ['query']), 40 | 'getAllowanceSize' : IDL.Func([], [IDL.Nat64], ['query']), 41 | 'getHolders' : IDL.Func( 42 | [IDL.Nat64, IDL.Nat64], 43 | [IDL.Vec(IDL.Tuple(IDL.Principal, IDL.Nat))], 44 | ['query'], 45 | ), 46 | 'getLogo' : IDL.Func([], [IDL.Text], ['query']), 47 | 'getMetadata' : IDL.Func([], [Metadata], ['query']), 48 | 'getTokenInfo' : IDL.Func([], [TokenInfo], ['query']), 49 | 'getUserApprovals' : IDL.Func( 50 | [IDL.Principal], 51 | [IDL.Vec(IDL.Tuple(IDL.Principal, IDL.Nat))], 52 | ['query'], 53 | ), 54 | 'historySize' : IDL.Func([], [IDL.Nat64], ['query']), 55 | 'mint' : IDL.Func([IDL.Opt(IDL.Vec(IDL.Nat8)), IDL.Nat64], [TxReceipt], []), 56 | 'name' : IDL.Func([], [IDL.Text], ['query']), 57 | 'owner' : IDL.Func([], [IDL.Principal], ['query']), 58 | 'setFee' : IDL.Func([IDL.Nat], [], []), 59 | 'setFeeTo' : IDL.Func([IDL.Principal], [], []), 60 | 'setLogo' : IDL.Func([IDL.Text], [], []), 61 | 'setName' : IDL.Func([IDL.Text], [], []), 62 | 'setOwner' : IDL.Func([IDL.Principal], [], []), 63 | 'symbol' : IDL.Func([], [IDL.Text], ['query']), 64 | 'totalSupply' : IDL.Func([], [IDL.Nat], ['query']), 65 | 'transfer' : IDL.Func([IDL.Principal, IDL.Nat], [TxReceipt], []), 66 | 'transferFrom' : IDL.Func( 67 | [IDL.Principal, IDL.Principal, IDL.Nat], 68 | [TxReceipt], 69 | [], 70 | ), 71 | 'withdraw' : IDL.Func([IDL.Nat64, IDL.Text], [TxReceipt], []), 72 | }); 73 | }; 74 | export const init = ({ IDL }) => { 75 | return [ 76 | IDL.Text, 77 | IDL.Text, 78 | IDL.Text, 79 | IDL.Nat8, 80 | IDL.Nat, 81 | IDL.Principal, 82 | IDL.Nat, 83 | IDL.Principal, 84 | IDL.Principal, 85 | ]; 86 | }; -------------------------------------------------------------------------------- /src/idls/xtc.did.ts: -------------------------------------------------------------------------------- 1 | export default ({ IDL }) => { 2 | const TxError = IDL.Variant({ 3 | 'InsufficientAllowance' : IDL.Null, 4 | 'InsufficientBalance' : IDL.Null, 5 | 'ErrorOperationStyle' : IDL.Null, 6 | 'Unauthorized' : IDL.Null, 7 | 'LedgerTrap' : IDL.Null, 8 | 'ErrorTo' : IDL.Null, 9 | 'Other' : IDL.Null, 10 | 'BlockUsed' : IDL.Null, 11 | 'AmountTooSmall' : IDL.Null, 12 | }); 13 | const TxReceipt = IDL.Variant({ 'Ok' : IDL.Nat, 'Err' : TxError }); 14 | const TransactionId = IDL.Nat64; 15 | const BurnError = IDL.Variant({ 16 | 'InsufficientBalance' : IDL.Null, 17 | 'InvalidTokenContract' : IDL.Null, 18 | 'NotSufficientLiquidity' : IDL.Null, 19 | }); 20 | const BurnResult = IDL.Variant({ 'Ok' : TransactionId, 'Err' : BurnError }); 21 | const TransactionStatus = IDL.Variant({ 22 | 'FAILED' : IDL.Null, 23 | 'SUCCEEDED' : IDL.Null, 24 | }); 25 | const EventDetail = IDL.Variant({ 26 | 'Approve' : IDL.Record({ 'to' : IDL.Principal, 'from' : IDL.Principal }), 27 | 'Burn' : IDL.Record({ 'to' : IDL.Principal, 'from' : IDL.Principal }), 28 | 'Mint' : IDL.Record({ 'to' : IDL.Principal }), 29 | 'CanisterCreated' : IDL.Record({ 30 | 'from' : IDL.Principal, 31 | 'canister' : IDL.Principal, 32 | }), 33 | 'CanisterCalled' : IDL.Record({ 34 | 'from' : IDL.Principal, 35 | 'method_name' : IDL.Text, 36 | 'canister' : IDL.Principal, 37 | }), 38 | 'Transfer' : IDL.Record({ 'to' : IDL.Principal, 'from' : IDL.Principal }), 39 | 'TransferFrom' : IDL.Record({ 40 | 'to' : IDL.Principal, 41 | 'from' : IDL.Principal, 42 | 'caller' : IDL.Principal, 43 | }), 44 | }); 45 | const Event = IDL.Record({ 46 | 'fee' : IDL.Nat64, 47 | 'status' : TransactionStatus, 48 | 'kind' : EventDetail, 49 | 'cycles' : IDL.Nat64, 50 | 'timestamp' : IDL.Nat64, 51 | }); 52 | const EventsConnection = IDL.Record({ 53 | 'data' : IDL.Vec(Event), 54 | 'next_offset' : TransactionId, 55 | 'next_canister_id' : IDL.Opt(IDL.Principal), 56 | }); 57 | const Metadata = IDL.Record({ 58 | 'fee' : IDL.Nat, 59 | 'decimals' : IDL.Nat8, 60 | 'owner' : IDL.Principal, 61 | 'logo' : IDL.Text, 62 | 'name' : IDL.Text, 63 | 'totalSupply' : IDL.Nat, 64 | 'symbol' : IDL.Text, 65 | }); 66 | const Operation = IDL.Variant({ 67 | 'transferFrom' : IDL.Null, 68 | 'burn' : IDL.Null, 69 | 'mint' : IDL.Null, 70 | 'approve' : IDL.Null, 71 | 'canisterCalled' : IDL.Null, 72 | 'transfer' : IDL.Null, 73 | 'canisterCreated' : IDL.Null, 74 | }); 75 | const Time = IDL.Int; 76 | const TxRecord = IDL.Record({ 77 | 'op' : Operation, 78 | 'to' : IDL.Principal, 79 | 'fee' : IDL.Nat, 80 | 'status' : TransactionStatus, 81 | 'from' : IDL.Principal, 82 | 'timestamp' : Time, 83 | 'caller' : IDL.Opt(IDL.Principal), 84 | 'index' : IDL.Nat, 85 | 'amount' : IDL.Nat, 86 | }); 87 | const MintError = IDL.Variant({ 'NotSufficientLiquidity' : IDL.Null }); 88 | const MintResult = IDL.Variant({ 'Ok' : TransactionId, 'Err' : MintError }); 89 | const Stats = IDL.Record({ 90 | 'fee' : IDL.Nat, 91 | 'transfers_count' : IDL.Nat64, 92 | 'balance' : IDL.Nat64, 93 | 'mints_count' : IDL.Nat64, 94 | 'transfers_from_count' : IDL.Nat64, 95 | 'canisters_created_count' : IDL.Nat64, 96 | 'supply' : IDL.Nat, 97 | 'burns_count' : IDL.Nat64, 98 | 'approvals_count' : IDL.Nat64, 99 | 'proxy_calls_count' : IDL.Nat64, 100 | 'history_events' : IDL.Nat64, 101 | }); 102 | const ResultCall = IDL.Variant({ 103 | 'Ok' : IDL.Record({ 'return' : IDL.Vec(IDL.Nat8) }), 104 | 'Err' : IDL.Text, 105 | }); 106 | const CreateResult = IDL.Variant({ 107 | 'Ok' : IDL.Record({ 'canister_id' : IDL.Principal }), 108 | 'Err' : IDL.Text, 109 | }); 110 | const ResultSend = IDL.Variant({ 'Ok' : IDL.Null, 'Err' : IDL.Text }); 111 | return IDL.Service({ 112 | 'allowance' : IDL.Func( 113 | [IDL.Principal, IDL.Principal], 114 | [IDL.Nat], 115 | ['query'], 116 | ), 117 | 'approve' : IDL.Func([IDL.Principal, IDL.Nat], [TxReceipt], []), 118 | 'balance' : IDL.Func([IDL.Opt(IDL.Principal)], [IDL.Nat64], []), 119 | 'balanceOf' : IDL.Func([IDL.Principal], [IDL.Nat], ['query']), 120 | 'burn' : IDL.Func( 121 | [IDL.Record({ 'canister_id' : IDL.Principal, 'amount' : IDL.Nat64 })], 122 | [BurnResult], 123 | [], 124 | ), 125 | 'decimals' : IDL.Func([], [IDL.Nat8], ['query']), 126 | 'events' : IDL.Func( 127 | [IDL.Record({ 'offset' : IDL.Opt(IDL.Nat64), 'limit' : IDL.Nat16 })], 128 | [EventsConnection], 129 | ['query'], 130 | ), 131 | 'getMetadata' : IDL.Func([], [Metadata], ['query']), 132 | 'getTransaction' : IDL.Func([IDL.Nat], [TxRecord], []), 133 | 'getTransactions' : IDL.Func([IDL.Nat, IDL.Nat], [IDL.Vec(TxRecord)], []), 134 | 'get_transaction' : IDL.Func([TransactionId], [IDL.Opt(Event)], []), 135 | 'halt' : IDL.Func([], [], []), 136 | 'historySize' : IDL.Func([], [IDL.Nat], ['query']), 137 | 'logo' : IDL.Func([], [IDL.Text], ['query']), 138 | 'mint' : IDL.Func([IDL.Principal, IDL.Nat], [MintResult], []), 139 | 'name' : IDL.Func([], [IDL.Text], ['query']), 140 | 'nameErc20' : IDL.Func([], [IDL.Text], ['query']), 141 | 'stats' : IDL.Func([], [Stats], ['query']), 142 | 'symbol' : IDL.Func([], [IDL.Text], ['query']), 143 | 'totalSupply' : IDL.Func([], [IDL.Nat], ['query']), 144 | 'transfer' : IDL.Func([IDL.Principal, IDL.Nat], [TxReceipt], []), 145 | 'transferErc20' : IDL.Func([IDL.Principal, IDL.Nat], [TxReceipt], []), 146 | 'transferFrom' : IDL.Func( 147 | [IDL.Principal, IDL.Principal, IDL.Nat], 148 | [TxReceipt], 149 | [], 150 | ), 151 | 'wallet_balance' : IDL.Func( 152 | [], 153 | [IDL.Record({ 'amount' : IDL.Nat64 })], 154 | ['query'], 155 | ), 156 | 'wallet_call' : IDL.Func( 157 | [ 158 | IDL.Record({ 159 | 'args' : IDL.Vec(IDL.Nat8), 160 | 'cycles' : IDL.Nat64, 161 | 'method_name' : IDL.Text, 162 | 'canister' : IDL.Principal, 163 | }), 164 | ], 165 | [ResultCall], 166 | [], 167 | ), 168 | 'wallet_create_canister' : IDL.Func( 169 | [ 170 | IDL.Record({ 171 | 'controller' : IDL.Opt(IDL.Principal), 172 | 'cycles' : IDL.Nat64, 173 | }), 174 | ], 175 | [CreateResult], 176 | [], 177 | ), 178 | 'wallet_create_wallet' : IDL.Func( 179 | [ 180 | IDL.Record({ 181 | 'controller' : IDL.Opt(IDL.Principal), 182 | 'cycles' : IDL.Nat64, 183 | }), 184 | ], 185 | [CreateResult], 186 | [], 187 | ), 188 | 'wallet_send' : IDL.Func( 189 | [IDL.Record({ 'canister' : IDL.Principal, 'amount' : IDL.Nat64 })], 190 | [ResultSend], 191 | [], 192 | ), 193 | }); 194 | }; 195 | export const init = () => { return []; }; 196 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './registries'; 2 | export * from './interfaces/nft'; 3 | export * from './interfaces/token'; 4 | export * as NFTInterfaces from './interfaces/nft'; 5 | export * as TokenInterfaces from './interfaces/token' 6 | export { default as standards } from './constants/standards'; 7 | export { Principal } from '@dfinity/principal'; 8 | export { HttpAgent } from '@dfinity/agent'; 9 | -------------------------------------------------------------------------------- /src/interfaces/c3.ts: -------------------------------------------------------------------------------- 1 | import { Principal } from '@dfinity/principal'; 2 | 3 | export interface TransferResponse { 4 | 'ok' : bigint, 5 | 'err' : Error, 6 | }; 7 | export interface Error { 8 | 'NotFoundIndex' : null, 9 | 'ListOnMarketPlace' : null, 10 | 'NotAllowTransferToSelf' : null, 11 | 'NotOwnerOrNotApprove' : null, 12 | 'Other' : null, 13 | }; 14 | export interface TokenDetails { 15 | 'id' : bigint, 16 | 'rarityScore' : number 17 | }; 18 | export interface GetTokenResponse { 19 | 'ok' : TokenDetails, 20 | 'err' : Error, 21 | }; 22 | export interface Property { 23 | value: string; 24 | name: string; 25 | }; 26 | export default interface _SERVICE { 27 | getTokenById: (token_index: bigint) => Promise; 28 | transferFrom: (from: Principal, to: Principal, tokenIndex: bigint) => Promise; 29 | getAllNFT: (user: Principal) => Promise>>; 30 | getNftStoreCIDByIndex: (token_index: bigint) => Promise; 31 | } 32 | -------------------------------------------------------------------------------- /src/interfaces/dab_nfts.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable camelcase */ 2 | /* eslint-disable @typescript-eslint/class-name-casing */ 3 | import { Principal } from '@dfinity/principal'; 4 | 5 | export type GetAllResult = DABCollection[]; 6 | 7 | export interface DABCollection { 8 | 'icon' : string, 9 | 'name' : string, 10 | 'description' : string, 11 | 'principal_id' : Principal, 12 | 'standard' : string, 13 | }; 14 | export interface NFTCanister { 15 | 'icon' : string, 16 | 'name' : string, 17 | 'description' : string, 18 | 'timestamp' : bigint, 19 | 'principal_id' : Principal, 20 | 'standard' : string, 21 | }; 22 | export type OperationError = { 'NotAuthorized' : null } | 23 | { 'BadParameters' : null } | 24 | { 'NonExistentItem' : null } | 25 | { 'ParamatersNotPassed' : null }; 26 | export type OperationResponse = { 'Ok' : boolean } | 27 | { 'Err' : OperationError }; 28 | export default interface _SERVICE { 29 | 'add' : (arg_0: DABCollection) => Promise, 30 | 'edit' : ( 31 | arg_0: string, 32 | arg_1: [] | [Principal], 33 | arg_2: [] | [string], 34 | arg_3: [] | [string], 35 | arg_4: [] | [string], 36 | ) => Promise, 37 | 'get_all' : () => Promise, 38 | 'get_canister' : (arg_0: string) => Promise<[] | [NFTCanister]>, 39 | 'name' : () => Promise, 40 | 'remove' : (arg_0: string) => Promise, 41 | }; -------------------------------------------------------------------------------- /src/interfaces/dab_registries/address_book.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | 3 | export type ValueType = { 'PrincipalId': Principal } | { 'AccountId': string } | { 'Icns': string } 4 | 5 | export interface Address { 6 | 'name': string, 7 | 'description': [] | [string], 8 | 'emoji': [] | [string], 9 | 'value': ValueType, 10 | } 11 | 12 | export type Error = { 'NotAuthorized' : null } | 13 | { 'BadParameters' : null } | 14 | { 'Unknown' : string } | 15 | { 'NonExistentItem' : null }; 16 | 17 | export type Response = { 'Ok' : [] | [string] } | 18 | { 'Err' : Error }; 19 | 20 | export default interface AddressBookInterface { 21 | 'add' : (arg_1: Address) => Promise, 22 | 'get_all' : () => Promise>, 23 | 'name' : () => Promise, 24 | 'remove' : (arg_0: String) => Promise, 25 | } 26 | -------------------------------------------------------------------------------- /src/interfaces/dab_registries/canister_registry.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | import RegistryStandard from './registry_standard'; 3 | 4 | export interface CanisterMetadata { 5 | 'thumbnail' : string, 6 | 'name' : string, 7 | 'frontend' : [] | [string], 8 | 'description' : string, 9 | 'principal_id' : Principal, 10 | 'details' : Array<[string, DetailValue]>, 11 | } 12 | export type DetailType = bigint | Array | Array | string | true | false | number | Principal 13 | 14 | export type DetailValue = { 'I64' : bigint } | 15 | { 'U64' : bigint } | 16 | { 'Vec' : Array } | 17 | { 'Slice' : Array } | 18 | { 'Text' : string } | 19 | { 'True' : null } | 20 | { 'False' : null } | 21 | { 'Float' : number } | 22 | { 'Principal' : Principal }; 23 | export type OperationError = { 'NotAuthorized' : null } | 24 | { 'BadParameters' : null } | 25 | { 'Unknown' : string } | 26 | { 'NonExistentItem' : null }; 27 | export type OperationResponse = { 'Ok' : [] | [string] } | 28 | { 'Err' : OperationError }; 29 | export default interface CanisterRegistry extends RegistryStandard { 30 | 'add' : (arg_1: CanisterMetadata) => Promise< 31 | OperationResponse 32 | >, 33 | 'get' : (arg_0: Principal) => Promise<[] | [CanisterMetadata]>, 34 | 'get_all' : () => Promise>, 35 | 'name' : () => Promise, 36 | 'remove' : (arg_0: Principal) => Promise, 37 | } 38 | -------------------------------------------------------------------------------- /src/interfaces/dab_registries/nft_registry.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | import RegistryStandard from './registry_standard'; 3 | 4 | export type DetailValue = { 'I64' : bigint } | 5 | { 'U64' : bigint } | 6 | { 'Vec' : Array } | 7 | { 'Slice' : Array } | 8 | { 'Text' : string } | 9 | { 'True' : null } | 10 | { 'False' : null } | 11 | { 'Float' : number } | 12 | { 'Principal' : Principal }; 13 | 14 | export interface NFTCanisterMetadata { 15 | 'thumbnail' : string, 16 | 'name' : string, 17 | 'frontend' : [] | [string], 18 | 'description' : string, 19 | 'principal_id' : Principal, 20 | 'details' : Array<[string, DetailValue]>, 21 | } 22 | export type Error = { 'NotAuthorized' : null } | 23 | { 'BadParameters' : null } | 24 | { 'Unknown' : string } | 25 | { 'NonExistentItem' : null }; 26 | export type Response = { 'Ok' : [] | [string] } | 27 | { 'Err' : Error }; 28 | export default interface NFTRegistryInterface extends RegistryStandard { 29 | 'add' : (arg_1: NFTCanisterMetadata) => Promise, 30 | 'edit' : ( 31 | arg_0: Principal, 32 | arg_1: [] | [string], 33 | arg_2: [] | [string], 34 | arg_3: [] | [string], 35 | arg_4: [] | [string], 36 | ) => Promise, 37 | 'get' : (arg_0: Principal) => Promise<[] | [NFTCanisterMetadata]>, 38 | 'get_all' : () => Promise>, 39 | 'name' : () => Promise, 40 | 'remove' : (arg_0: Principal) => Promise, 41 | 'set_controller' : (arg_0: Principal) => Promise, 42 | } 43 | -------------------------------------------------------------------------------- /src/interfaces/dab_registries/registry_standard.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | export type DetailType = bigint | Array | Array | string | true | false | number | Principal 3 | export type DetailValue = { 'I64' : bigint } | 4 | { 'U64' : bigint } | 5 | { 'Vec' : Array } | 6 | { 'Slice' : Array } | 7 | { 'Text' : string } | 8 | { 'True' : null } | 9 | { 'False' : null } | 10 | { 'Float' : number } | 11 | { 'Principal' : Principal }; 12 | export type Error = { 'NotAuthorized' : null } | 13 | { 'BadParameters' : null } | 14 | { 'Unknown' : string } | 15 | { 'NonExistentItem' : null }; 16 | export interface Metadata { 17 | 'thumbnail' : string, 18 | 'name' : string, 19 | 'frontend' : [] | [string], 20 | 'description' : string, 21 | 'principal_id' : Principal, 22 | 'details' : Array<[string, DetailValue]>, 23 | } 24 | export type Response = { 'Ok' : [] | [string] } | 25 | { 'Err' : Error }; 26 | export default interface RegistryStandard { 27 | 'add' : (arg_1: Metadata) => Promise, 28 | 'get' : (arg_0: Principal) => Promise<[] | [Metadata]>, 29 | 'name' : () => Promise, 30 | 'remove' : (arg_0: Principal) => Promise, 31 | } 32 | -------------------------------------------------------------------------------- /src/interfaces/dab_registries/token_registry.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | import RegistryStandard from './registry_standard'; 3 | export type detail_value = { 'I64' : bigint } | 4 | { 'U64' : bigint } | 5 | { 'Vec' : Array } | 6 | { 'Slice' : Array } | 7 | { 'Text' : string } | 8 | { 'True' : null } | 9 | { 'False' : null } | 10 | { 'Float' : number } | 11 | { 'Principal' : Principal }; 12 | export type operation_error = { 'NotAuthorized' : null } | 13 | { 'BadParameters' : null } | 14 | { 'Unknown' : string } | 15 | { 'NonExistentItem' : null }; 16 | export type operation_response = { 'Ok' : [] | [string] } | 17 | { 'Err' : operation_error }; 18 | export interface token { 19 | 'thumbnail' : string, 20 | 'name' : string, 21 | 'frontend' : [] | [string], 22 | 'description' : string, 23 | 'principal_id' : Principal, 24 | 'details' : Array<[string, detail_value]>, 25 | } 26 | export default interface TokenRegistry extends RegistryStandard { 27 | 'add' : (arg_1: token) => Promise, 28 | 'get' : (arg_0: Principal) => Promise<[] | [token]>, 29 | 'get_all' : () => Promise>, 30 | 'name' : () => Promise, 31 | 'remove' : (arg_0: Principal) => Promise, 32 | 'set_controller' : (arg_0: Principal) => Promise, 33 | } 34 | -------------------------------------------------------------------------------- /src/interfaces/departure_labs.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | export type AssetRequest = { 3 | 'Put' : { 4 | 'key' : string, 5 | 'contentType' : string, 6 | 'callback' : [] | [Callback], 7 | 'payload' : { 'StagedData' : null } | 8 | { 'Payload' : Array }, 9 | } 10 | } | 11 | { 'Remove' : { 'key' : string, 'callback' : [] | [Callback] } } | 12 | { 'StagedWrite' : StagedWrite }; 13 | export interface AuthorizeRequest { 14 | 'p' : Principal, 15 | 'id' : string, 16 | 'isAuthorized' : boolean, 17 | } 18 | export type Callback = () => Promise; 19 | export interface CallbackStatus { 20 | 'failedCalls' : bigint, 21 | 'failedCallsLimit' : bigint, 22 | 'callback' : [] | [Callback__1], 23 | 'noTopupCallLimit' : bigint, 24 | 'callsSinceLastTopup' : bigint, 25 | } 26 | export type Callback__1 = (arg_0: Message) => Promise; 27 | export interface Chunk { 28 | 'data' : Array, 29 | 'totalPages' : bigint, 30 | 'nextPage' : [] | [bigint], 31 | } 32 | export type Contract = { 33 | 'ContractAuthorize' : { 'isAuthorized' : boolean, 'user' : Principal } 34 | } | 35 | { 'Mint' : { 'id' : string, 'owner' : Principal } }; 36 | export interface ContractInfo { 37 | 'nft_payload_size' : bigint, 38 | 'memory_size' : bigint, 39 | 'max_live_size' : bigint, 40 | 'cycles' : bigint, 41 | 'total_minted' : bigint, 42 | 'heap_size' : bigint, 43 | 'authorized_users' : Array, 44 | } 45 | export interface ContractMetadata { 'name' : string, 'symbol' : string } 46 | export interface Egg { 47 | 'contentType' : string, 48 | 'owner' : [] | [Principal], 49 | 'properties' : Properties, 50 | 'isPrivate' : boolean, 51 | 'payload' : { 'StagedData' : null } | 52 | { 'Payload' : Array }, 53 | } 54 | export type Error = { 'Immutable' : null } | 55 | { 'NotFound' : null } | 56 | { 'Unauthorized' : null } | 57 | { 'InvalidRequest' : null } | 58 | { 'AuthorizedPrincipalLimitReached' : bigint }; 59 | export type HeaderField = [string, string]; 60 | export interface Hub { 61 | 'assetRequest' : (arg_0: AssetRequest) => Promise, 62 | 'authorize' : (arg_0: AuthorizeRequest) => Promise, 63 | 'balanceOf' : (arg_0: Principal) => Promise>, 64 | 'getAuthorized' : (arg_0: string) => Promise>, 65 | 'getContractInfo' : () => Promise, 66 | 'getEventCallbackStatus' : () => Promise, 67 | 'getMetadata' : () => Promise, 68 | 'getTotalMinted' : () => Promise, 69 | 'http_request' : (arg_0: Request) => Promise, 70 | 'http_request_streaming_callback' : ( 71 | arg_0: StreamingCallbackToken, 72 | ) => Promise, 73 | 'init' : (arg_0: Array, arg_1: ContractMetadata) => Promise< 74 | undefined 75 | >, 76 | 'isAuthorized' : (arg_0: string, arg_1: Principal) => Promise, 77 | 'listAssets' : () => Promise>, 78 | 'mint' : (arg_0: Egg) => Promise, 79 | 'nftStreamingCallback' : (arg_0: StreamingCallbackToken) => Promise< 80 | StreamingCallbackResponse 81 | >, 82 | 'ownerOf' : (arg_0: string) => Promise, 83 | 'queryProperties' : (arg_0: QueryRequest) => Promise, 84 | 'staticStreamingCallback' : (arg_0: StreamingCallbackToken) => Promise< 85 | StreamingCallbackResponse 86 | >, 87 | 'tokenByIndex' : (arg_0: string) => Promise, 88 | 'tokenChunkByIndex' : (arg_0: string, arg_1: bigint) => Promise, 89 | 'tokenMetadataByIndex' : (arg_0: string) => Promise, 90 | 'transfer' : (arg_0: Principal, arg_1: string) => Promise, 91 | 'updateContractOwners' : (arg_0: Principal, arg_1: boolean) => Promise< 92 | Result_1 93 | >, 94 | 'updateEventCallback' : (arg_0: UpdateEventCallback) => Promise, 95 | 'updateProperties' : (arg_0: UpdateRequest) => Promise, 96 | 'wallet_receive' : () => Promise, 97 | 'writeStaged' : (arg_0: StagedWrite) => Promise, 98 | } 99 | export interface Message { 100 | 'topupCallback' : TopupCallback, 101 | 'createdAt' : bigint, 102 | 'topupAmount' : bigint, 103 | 'event' : { 'ContractEvent' : Contract } | 104 | { 'TokenEvent' : Token }, 105 | } 106 | export interface Metadata { 107 | 'id' : string, 108 | 'contentType' : string, 109 | 'owner' : Principal, 110 | 'createdAt' : bigint, 111 | 'properties' : Properties, 112 | } 113 | export type PayloadResult = { 'Complete' : Array } | 114 | { 'Chunk' : Chunk }; 115 | export type Properties = Array; 116 | export interface Property { 117 | 'value' : Value, 118 | 'name' : string, 119 | 'immutable' : boolean, 120 | } 121 | export interface PublicToken { 122 | 'id' : string, 123 | 'contentType' : string, 124 | 'owner' : Principal, 125 | 'createdAt' : bigint, 126 | 'properties' : Properties, 127 | 'payload' : PayloadResult, 128 | } 129 | export interface Query { 'name' : string, 'next' : Array } 130 | export type QueryMode = { 'All' : null } | 131 | { 'Some' : Array }; 132 | export interface QueryRequest { 'id' : string, 'mode' : QueryMode } 133 | export interface Request { 134 | 'url' : string, 135 | 'method' : string, 136 | 'body' : Array, 137 | 'headers' : Array, 138 | } 139 | export interface Response { 140 | 'body' : Array, 141 | 'headers' : Array, 142 | 'streaming_strategy' : [] | [StreamingStrategy], 143 | 'status_code' : number, 144 | } 145 | export type Result = { 'ok' : Properties } | 146 | { 'err' : Error }; 147 | export type Result_1 = { 'ok' : null } | 148 | { 'err' : Error }; 149 | export type Result_2 = { 'ok' : Metadata } | 150 | { 'err' : Error }; 151 | export type Result_3 = { 'ok' : Chunk } | 152 | { 'err' : Error }; 153 | export type Result_4 = { 'ok' : PublicToken } | 154 | { 'err' : Error }; 155 | export type Result_5 = { 'ok' : Principal } | 156 | { 'err' : Error }; 157 | export type StagedWrite = { 158 | 'Init' : { 'size' : bigint, 'callback' : [] | [Callback] } 159 | } | 160 | { 'Chunk' : { 'chunk' : Array, 'callback' : [] | [Callback] } }; 161 | export type StreamingCallback = (arg_0: StreamingCallbackToken) => Promise< 162 | StreamingCallbackResponse 163 | >; 164 | export interface StreamingCallbackResponse { 165 | 'token' : [] | [StreamingCallbackToken], 166 | 'body' : Array, 167 | } 168 | export interface StreamingCallbackToken { 169 | 'key' : string, 170 | 'index' : bigint, 171 | 'content_encoding' : string, 172 | } 173 | export type StreamingStrategy = { 174 | 'Callback' : { 175 | 'token' : StreamingCallbackToken, 176 | 'callback' : StreamingCallback, 177 | } 178 | }; 179 | export type Token = { 180 | 'Authorize' : { 181 | 'id' : string, 182 | 'isAuthorized' : boolean, 183 | 'user' : Principal, 184 | } 185 | } | 186 | { 'Transfer' : { 'id' : string, 'to' : Principal, 'from' : Principal } }; 187 | export type TopupCallback = () => Promise; 188 | export interface Update { 'mode' : UpdateMode, 'name' : string } 189 | export type UpdateEventCallback = { 'Set' : Callback__1 } | 190 | { 'Remove' : null }; 191 | export type UpdateMode = { 'Set' : Value } | 192 | { 'Next' : Array }; 193 | export interface UpdateRequest { 'id' : string, 'update' : Array } 194 | export type Value = { 'Int' : bigint } | 195 | { 'Nat' : bigint } | 196 | { 'Empty' : null } | 197 | { 'Bool' : boolean } | 198 | { 'Text' : string } | 199 | { 'Float' : number } | 200 | { 'Principal' : Principal } | 201 | { 'Class' : Array }; 202 | export default interface _SERVICE extends Hub {} 203 | -------------------------------------------------------------------------------- /src/interfaces/dip_20.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | export interface Metadata { 3 | 'fee' : bigint, 4 | 'decimals' : number, 5 | 'owner' : Principal, 6 | 'logo' : string, 7 | 'name' : string, 8 | 'totalSupply' : bigint, 9 | 'symbol' : string, 10 | } 11 | export type Result = { 'Ok' : bigint } | 12 | { 'Err' : TxError }; 13 | export interface TokenInfo { 14 | 'holderNumber' : bigint, 15 | 'deployTime' : bigint, 16 | 'metadata' : Metadata, 17 | 'historySize' : bigint, 18 | 'cycles' : bigint, 19 | 'feeTo' : Principal, 20 | } 21 | export type TxError = { 'InsufficientAllowance' : null } | 22 | { 'InsufficientBalance' : null } | 23 | { 'ErrorOperationStyle' : null } | 24 | { 'Unauthorized' : null } | 25 | { 'LedgerTrap' : null } | 26 | { 'ErrorTo' : null } | 27 | { 'Other' : null } | 28 | { 'BlockUsed' : null } | 29 | { 'AmountTooSmall' : null }; 30 | export default interface _SERVICE { 31 | 'allowance' : (arg_0: Principal, arg_1: Principal) => Promise, 32 | 'approve' : (arg_0: Principal, arg_1: bigint) => Promise, 33 | 'balanceOf' : (arg_0: Principal) => Promise, 34 | 'decimals' : () => Promise, 35 | 'getAllowanceSize' : () => Promise, 36 | 'getBlockUsed' : () => Promise>, 37 | 'getHolders' : (arg_0: bigint, arg_1: bigint) => Promise< 38 | Array<[Principal, bigint]> 39 | >, 40 | 'getMetadata' : () => Promise, 41 | 'getTokenInfo' : () => Promise, 42 | 'getUserApprovals' : (arg_0: Principal) => Promise< 43 | Array<[Principal, bigint]> 44 | >, 45 | 'historySize' : () => Promise, 46 | 'isBlockUsed' : (arg_0: bigint) => Promise, 47 | 'logo' : () => Promise, 48 | 'mint' : (arg_0: [] | [Array], arg_1: bigint) => Promise, 49 | 'mintFor' : ( 50 | arg_0: [] | [Array], 51 | arg_1: bigint, 52 | arg_2: Principal, 53 | ) => Promise, 54 | 'name' : () => Promise, 55 | 'owner' : () => Promise, 56 | 'setFee' : (arg_0: bigint) => Promise, 57 | 'setFeeTo' : (arg_0: Principal) => Promise, 58 | 'setGenesis' : () => Promise, 59 | 'setLogo' : (arg_0: string) => Promise, 60 | 'setName' : (arg_0: string) => Promise, 61 | 'setOwner' : (arg_0: Principal) => Promise, 62 | 'symbol' : () => Promise, 63 | 'totalSupply' : () => Promise, 64 | 'transfer' : (arg_0: Principal, arg_1: bigint) => Promise, 65 | 'transferFrom' : ( 66 | arg_0: Principal, 67 | arg_1: Principal, 68 | arg_2: bigint, 69 | ) => Promise, 70 | 'withdraw' : (arg_0: bigint, arg_1: string) => Promise, 71 | } 72 | -------------------------------------------------------------------------------- /src/interfaces/dip_721.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | import type { ActorMethod } from '@dfinity/agent'; 3 | 4 | export type GenericValue = { 'Nat64Content' : bigint } | 5 | { 'Nat32Content' : number } | 6 | { 'BoolContent' : boolean } | 7 | { 'Nat8Content' : number } | 8 | { 'Int64Content' : bigint } | 9 | { 'IntContent' : bigint } | 10 | { 'NatContent' : bigint } | 11 | { 'Nat16Content' : number } | 12 | { 'Int32Content' : number } | 13 | { 'Int8Content' : number } | 14 | { 'FloatContent' : number } | 15 | { 'Int16Content' : number } | 16 | { 'BlobContent' : Array } | 17 | { 'NestedContent' : Vec } | 18 | { 'Principal' : Principal } | 19 | { 'TextContent' : string }; 20 | export interface InitArgs { 21 | 'cap' : [] | [Principal], 22 | 'logo' : [] | [string], 23 | 'name' : [] | [string], 24 | 'custodians' : [] | [Array], 25 | 'symbol' : [] | [string], 26 | } 27 | export interface ManualReply { 28 | 'logo' : [] | [string], 29 | 'name' : [] | [string], 30 | 'created_at' : bigint, 31 | 'upgraded_at' : bigint, 32 | 'custodians' : Array, 33 | 'symbol' : [] | [string], 34 | } 35 | export type ManualReply_1 = { 'Ok' : Array } | 36 | { 'Err' : NftError }; 37 | export type ManualReply_2 = { 'Ok' : Array } | 38 | { 'Err' : NftError }; 39 | export type ManualReply_3 = { 'Ok' : TokenMetadata } | 40 | { 'Err' : NftError }; 41 | export type NftError = { 'UnauthorizedOperator' : null } | 42 | { 'SelfTransfer' : null } | 43 | { 'TokenNotFound' : null } | 44 | { 'UnauthorizedOwner' : null } | 45 | { 'SelfApprove' : null } | 46 | { 'OperatorNotFound' : null } | 47 | { 'ExistedNFT' : null } | 48 | { 'OwnerNotFound' : null }; 49 | export type Result = { 'Ok' : bigint } | 50 | { 'Err' : NftError }; 51 | export type Result_1 = { 'Ok' : boolean } | 52 | { 'Err' : NftError }; 53 | export type Result_2 = { 'Ok' : [] | [Principal] } | 54 | { 'Err' : NftError }; 55 | export interface Stats { 56 | 'cycles' : bigint, 57 | 'total_transactions' : bigint, 58 | 'total_unique_holders' : bigint, 59 | 'total_supply' : bigint, 60 | } 61 | export type SupportedInterface = { 'Burn' : null } | 62 | { 'Mint' : null } | 63 | { 'Approval' : null }; 64 | export interface TokenMetadata { 65 | 'transferred_at' : [] | [bigint], 66 | 'transferred_by' : [] | [Principal], 67 | 'owner' : [] | [Principal], 68 | 'operator' : [] | [Principal], 69 | 'approved_at' : [] | [bigint], 70 | 'approved_by' : [] | [Principal], 71 | 'properties' : Array<[string, GenericValue]>, 72 | 'is_burned' : boolean, 73 | 'token_identifier' : bigint, 74 | 'burned_at' : [] | [bigint], 75 | 'burned_by' : [] | [Principal], 76 | 'minted_at' : bigint, 77 | 'minted_by' : Principal, 78 | } 79 | export type Vec = Array< 80 | [ 81 | string, 82 | { 'Nat64Content' : bigint } | 83 | { 'Nat32Content' : number } | 84 | { 'BoolContent' : boolean } | 85 | { 'Nat8Content' : number } | 86 | { 'Int64Content' : bigint } | 87 | { 'IntContent' : bigint } | 88 | { 'NatContent' : bigint } | 89 | { 'Nat16Content' : number } | 90 | { 'Int32Content' : number } | 91 | { 'Int8Content' : number } | 92 | { 'FloatContent' : number } | 93 | { 'Int16Content' : number } | 94 | { 'BlobContent' : Array } | 95 | { 'NestedContent' : Vec } | 96 | { 'Principal' : Principal } | 97 | { 'TextContent' : string }, 98 | ] 99 | >; 100 | export default interface _SERVICE { 101 | 'approve' : ActorMethod<[Principal, bigint], Result>, 102 | 'balanceOf' : ActorMethod<[Principal], Result>, 103 | 'burn' : ActorMethod<[bigint], Result>, 104 | 'custodians' : ActorMethod<[], Array>, 105 | 'cycles' : ActorMethod<[], bigint>, 106 | 'dfx_info' : ActorMethod<[], string>, 107 | 'dip721_approve' : ActorMethod<[Principal, bigint], Result>, 108 | 'dip721_balance_of' : ActorMethod<[Principal], Result>, 109 | 'dip721_burn' : ActorMethod<[bigint], Result>, 110 | 'dip721_custodians' : ActorMethod<[], Array>, 111 | 'dip721_cycles' : ActorMethod<[], bigint>, 112 | 'dip721_is_approved_for_all' : ActorMethod<[Principal, Principal], Result_1>, 113 | 'dip721_logo' : ActorMethod<[], [] | [string]>, 114 | 'dip721_metadata' : ActorMethod<[], ManualReply>, 115 | 'dip721_mint' : ActorMethod< 116 | [Principal, bigint, Array<[string, GenericValue]>], 117 | Result 118 | >, 119 | 'dip721_name' : ActorMethod<[], [] | [string]>, 120 | 'dip721_operator_of' : ActorMethod<[bigint], Result_2>, 121 | 'dip721_operator_token_identifiers' : ActorMethod<[Principal], ManualReply_1>, 122 | 'dip721_operator_token_metadata' : ActorMethod<[Principal], ManualReply_2>, 123 | 'dip721_owner_of' : ActorMethod<[bigint], Result_2>, 124 | 'dip721_owner_token_identifiers' : ActorMethod<[Principal], ManualReply_1>, 125 | 'dip721_owner_token_metadata' : ActorMethod<[Principal], ManualReply_2>, 126 | 'dip721_set_approval_for_all' : ActorMethod<[Principal, boolean], Result>, 127 | 'dip721_set_custodians' : ActorMethod<[Array], undefined>, 128 | 'dip721_set_logo' : ActorMethod<[string], undefined>, 129 | 'dip721_set_name' : ActorMethod<[string], undefined>, 130 | 'dip721_set_symbol' : ActorMethod<[string], undefined>, 131 | 'dip721_stats' : ActorMethod<[], Stats>, 132 | 'dip721_supported_interfaces' : ActorMethod<[], Array>, 133 | 'dip721_symbol' : ActorMethod<[], [] | [string]>, 134 | 'dip721_token_metadata' : ActorMethod<[bigint], ManualReply_3>, 135 | 'dip721_total_supply' : ActorMethod<[], bigint>, 136 | 'dip721_total_transactions' : ActorMethod<[], bigint>, 137 | 'dip721_total_unique_holders' : ActorMethod<[], bigint>, 138 | 'dip721_transfer' : ActorMethod<[Principal, bigint], Result>, 139 | 'dip721_transfer_from' : ActorMethod<[Principal, Principal, bigint], Result>, 140 | 'git_commit_hash' : ActorMethod<[], string>, 141 | 'isApprovedForAll' : ActorMethod<[Principal, Principal], Result_1>, 142 | 'logo' : ActorMethod<[], [] | [string]>, 143 | 'metadata' : ActorMethod<[], ManualReply>, 144 | 'mint' : ActorMethod< 145 | [Principal, bigint, Array<[string, GenericValue]>], 146 | Result 147 | >, 148 | 'name' : ActorMethod<[], [] | [string]>, 149 | 'operatorOf' : ActorMethod<[bigint], Result_2>, 150 | 'operatorTokenIdentifiers' : ActorMethod<[Principal], ManualReply_1>, 151 | 'operatorTokenMetadata' : ActorMethod<[Principal], ManualReply_2>, 152 | 'ownerOf' : ActorMethod<[bigint], Result_2>, 153 | 'ownerTokenIdentifiers' : ActorMethod<[Principal], ManualReply_1>, 154 | 'ownerTokenMetadata' : ActorMethod<[Principal], ManualReply_2>, 155 | 'rust_toolchain_info' : ActorMethod<[], string>, 156 | 'setApprovalForAll' : ActorMethod<[Principal, boolean], Result>, 157 | 'setCustodians' : ActorMethod<[Array], undefined>, 158 | 'setLogo' : ActorMethod<[string], undefined>, 159 | 'setName' : ActorMethod<[string], undefined>, 160 | 'setSymbol' : ActorMethod<[string], undefined>, 161 | 'stats' : ActorMethod<[], Stats>, 162 | 'supportedInterfaces' : ActorMethod<[], Array>, 163 | 'symbol' : ActorMethod<[], [] | [string]>, 164 | 'tokenMetadata' : ActorMethod<[bigint], ManualReply_3>, 165 | 'totalSupply' : ActorMethod<[], bigint>, 166 | 'totalTransactions' : ActorMethod<[], bigint>, 167 | 'totalUniqueHolders' : ActorMethod<[], bigint>, 168 | 'transfer' : ActorMethod<[Principal, bigint], Result>, 169 | 'transferFrom' : ActorMethod<[Principal, Principal, bigint], Result>, 170 | } 171 | -------------------------------------------------------------------------------- /src/interfaces/drc_20.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | import type { ActorMethod } from '@dfinity/agent'; 3 | 4 | export interface Account { 5 | owner: Principal; 6 | subaccount: [] | [Subaccount]; 7 | } 8 | export type AccountId = Uint8Array | number[]; 9 | export type Address = string; 10 | export interface Allowance { 11 | remaining: bigint; 12 | spender: AccountId; 13 | } 14 | export type Amount = bigint; 15 | export type Callback = ActorMethod<[TxnRecord], undefined>; 16 | export interface CoinSeconds { 17 | updateTime: bigint; 18 | coinSeconds: bigint; 19 | } 20 | export interface DRC20 { 21 | drc20_allowance: ActorMethod<[Address, Spender], Amount>; 22 | drc20_approvals: ActorMethod<[Address], Array>; 23 | drc20_approve: ActorMethod< 24 | [Spender, Amount, [] | [Nonce], [] | [Sa], [] | [Data]], 25 | TxnResult 26 | >; 27 | drc20_balanceOf: ActorMethod<[Address], Amount>; 28 | drc20_decimals: ActorMethod<[], number>; 29 | drc20_dropAccount: ActorMethod<[[] | [Sa]], boolean>; 30 | drc20_executeTransfer: ActorMethod< 31 | [Txid, ExecuteType, [] | [To], [] | [Nonce], [] | [Sa], [] | [Data]], 32 | TxnResult 33 | >; 34 | drc20_fee: ActorMethod<[], Amount>; 35 | drc20_getCoinSeconds: ActorMethod< 36 | [[] | [Address]], 37 | [CoinSeconds, [] | [CoinSeconds]] 38 | >; 39 | drc20_holdersCount: ActorMethod<[], [bigint, bigint, bigint]>; 40 | drc20_lockTransfer: ActorMethod< 41 | [To, Amount, Timeout, [] | [Decider], [] | [Nonce], [] | [Sa], [] | [Data]], 42 | TxnResult 43 | >; 44 | drc20_lockTransferFrom: ActorMethod< 45 | [ 46 | From, 47 | To, 48 | Amount, 49 | Timeout, 50 | [] | [Decider], 51 | [] | [Nonce], 52 | [] | [Sa], 53 | [] | [Data] 54 | ], 55 | TxnResult 56 | >; 57 | drc20_metadata: ActorMethod<[], Array>; 58 | drc20_name: ActorMethod<[], string>; 59 | drc20_subscribe: ActorMethod< 60 | [[Principal, string], Array, [] | [Sa]], 61 | boolean 62 | >; 63 | drc20_subscribed: ActorMethod<[Address], [] | [Subscription]>; 64 | drc20_symbol: ActorMethod<[], string>; 65 | drc20_totalSupply: ActorMethod<[], Amount>; 66 | drc20_transfer: ActorMethod< 67 | [To, Amount, [] | [Nonce], [] | [Sa], [] | [Data]], 68 | TxnResult 69 | >; 70 | drc20_transferBatch: ActorMethod< 71 | [Array, Array, [] | [Nonce], [] | [Sa], [] | [Data]], 72 | Array 73 | >; 74 | drc20_transferFrom: ActorMethod< 75 | [From, To, Amount, [] | [Nonce], [] | [Sa], [] | [Data]], 76 | TxnResult 77 | >; 78 | drc20_txnQuery: ActorMethod<[TxnQueryRequest], TxnQueryResponse>; 79 | drc20_txnRecord: ActorMethod<[Txid], [] | [TxnRecord]>; 80 | standard: ActorMethod<[], string>; 81 | } 82 | export type Data = Uint8Array | number[]; 83 | export type Decider = string; 84 | export type ExecuteType = 85 | | { fallback: null } 86 | | { send: bigint } 87 | | { sendAll: null }; 88 | export type From = string; 89 | export type Gas = { token: bigint } | { cycles: bigint } | { noFee: null }; 90 | export interface InitArgs { 91 | fee: bigint; 92 | decimals: number; 93 | metadata: [] | [Array]; 94 | name: [] | [string]; 95 | totalSupply: bigint; 96 | founder: [] | [Address]; 97 | symbol: [] | [string]; 98 | } 99 | export interface Metadata { 100 | content: string; 101 | name: string; 102 | } 103 | export type MsgType = 104 | | { onApprove: null } 105 | | { onExecute: null } 106 | | { onTransfer: null } 107 | | { onLock: null }; 108 | export type Nonce = bigint; 109 | export type Operation = 110 | | { approve: { allowance: bigint } } 111 | | { 112 | lockTransfer: { 113 | locked: bigint; 114 | expiration: Time; 115 | decider: AccountId; 116 | }; 117 | } 118 | | { 119 | transfer: { 120 | action: { burn: null } | { mint: null } | { send: null }; 121 | }; 122 | } 123 | | { executeTransfer: { fallback: bigint; lockedTxid: Txid } }; 124 | export type Sa = Uint8Array | number[]; 125 | export type Spender = string; 126 | export type Subaccount = Uint8Array | number[]; 127 | export interface Subscription { 128 | callback: Callback; 129 | msgTypes: Array; 130 | } 131 | export type Time = bigint; 132 | export type Timeout = number; 133 | export type Timestamp = bigint; 134 | export type To = string; 135 | export interface Transaction { 136 | to: AccountId; 137 | value: bigint; 138 | data: [] | [Uint8Array | number[]]; 139 | from: AccountId; 140 | operation: Operation; 141 | } 142 | export type Txid = Uint8Array | number[]; 143 | export type TxnQueryRequest = 144 | | { getEvents: { owner: [] | [Address] } } 145 | | { txnCount: { owner: Address } } 146 | | { lockedTxns: { owner: Address } } 147 | | { lastTxids: { owner: Address } } 148 | | { lastTxidsGlobal: null } 149 | | { getTxn: { txid: Txid } } 150 | | { txnCountGlobal: null }; 151 | export type TxnQueryResponse = 152 | | { getEvents: Array } 153 | | { txnCount: bigint } 154 | | { lockedTxns: { txns: Array; lockedBalance: bigint } } 155 | | { lastTxids: Array } 156 | | { lastTxidsGlobal: Array } 157 | | { getTxn: [] | [TxnRecord] } 158 | | { txnCountGlobal: bigint }; 159 | export interface TxnRecord { 160 | gas: Gas; 161 | msgCaller: [] | [Principal]; 162 | transaction: Transaction; 163 | txid: Txid; 164 | nonce: bigint; 165 | timestamp: Time; 166 | caller: AccountId; 167 | index: bigint; 168 | } 169 | export type TxnResult = 170 | | { ok: Txid } 171 | | { 172 | err: { 173 | code: 174 | | { NonceError: null } 175 | | { InsufficientGas: null } 176 | | { InsufficientAllowance: null } 177 | | { UndefinedError: null } 178 | | { InsufficientBalance: null } 179 | | { NoLockedTransfer: null } 180 | | { DuplicateExecutedTransfer: null } 181 | | { LockedTransferExpired: null }; 182 | message: string; 183 | }; 184 | }; 185 | export default interface _SERVICE extends DRC20 {} 186 | -------------------------------------------------------------------------------- /src/interfaces/ext.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/class-name-casing */ 2 | /* eslint-disable @typescript-eslint/camelcase */ 3 | /* eslint-disable camelcase */ 4 | import { Principal } from '@dfinity/principal'; 5 | 6 | export type AccountIdentifier = string; 7 | 8 | export type TokenIdentifier = string; 9 | 10 | export type Balance = bigint; 11 | 12 | export type SubAccount = number[]; 13 | 14 | export type Memo = number[]; 15 | 16 | export type Fee = bigint; 17 | 18 | export type Time = bigint; 19 | 20 | export type TokenIndex = number; 21 | 22 | export type Tokens = TokenIndex[]; 23 | 24 | export type User = 25 | | { 26 | addres?: AccountIdentifier; // No notification 27 | } 28 | | { 29 | principal?: Principal; // default to sub account 0 30 | }; 31 | 32 | export type CommonError = 33 | | { 34 | InvalidToken: TokenIdentifier; 35 | } 36 | | { 37 | Other: string; 38 | }; 39 | 40 | export interface ResultOk { 41 | ok: T; 42 | } 43 | 44 | export interface ResultError { 45 | err: T; 46 | } 47 | 48 | export type Result = ResultOk | ResultError; 49 | 50 | interface BalanceRequest { 51 | token: TokenIdentifier; 52 | user: User; 53 | } 54 | 55 | export interface Listing { 56 | locked?: Time; 57 | seller: Principal; 58 | price: bigint; 59 | } 60 | 61 | export interface TokenMetaData { 62 | name: string; 63 | decimals: number; 64 | symbol: string; 65 | fee?: number; 66 | } 67 | 68 | export type Extension = string; 69 | 70 | type Details = [AccountIdentifier, Listing]; 71 | 72 | type BalanceResult = Result; 73 | 74 | type DetailsResult = Result; 75 | 76 | type TokensResult = Result; 77 | 78 | type TokenExt = [TokenIndex, Listing[], Int8Array[]]; 79 | 80 | type TokensExtResult = Result; 81 | 82 | type SupplyResponse = Result; 83 | 84 | 85 | interface TransferRequest { 86 | to: User; 87 | from: User; 88 | token: TokenIdentifier; 89 | amount: Balance; 90 | memo: Memo; 91 | notify: boolean; 92 | subaccount?: SubAccount; 93 | fee: bigint; 94 | } 95 | 96 | type TransferError = 97 | | { Unauthorized: AccountIdentifier } 98 | | { InsufficientBalance: null } 99 | | { Rejected: null } 100 | | { InvalidToken: TokenIdentifier } 101 | | { CannotNotify: AccountIdentifier } 102 | | { Other: string }; 103 | 104 | type TransferResult = Result; 105 | 106 | export interface FungibleMetadata { 107 | fungible: TokenMetaData & { 108 | metadata?: Int8Array[]; 109 | }; 110 | } 111 | 112 | export interface NonFungibleMetadata { 113 | nonfungible: { 114 | metadata: Int8Array[]; 115 | }; 116 | } 117 | export type Metadata = FungibleMetadata | NonFungibleMetadata; 118 | 119 | export type MetadataResponse = Result; 120 | 121 | export default interface _SERVICE { 122 | extensions: () => Promise; 123 | balance: (arg_0: BalanceRequest) => Promise; 124 | details: (token: TokenIdentifier) => Promise; 125 | tokens: (account: AccountIdentifier) => Promise; 126 | tokens_ext: (account: AccountIdentifier) => Promise; 127 | transfer: (arg_0: TransferRequest) => Promise; 128 | metadata: (token: TokenIdentifier) => Promise; 129 | supply: (token: TokenIdentifier) => Promise; 130 | } 131 | export const init = () => { 132 | return []; 133 | }; 134 | -------------------------------------------------------------------------------- /src/interfaces/icpunks.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable camelcase */ 2 | /* eslint-disable @typescript-eslint/camelcase */ 3 | /* eslint-disable @typescript-eslint/class-name-casing */ 4 | /* eslint-disable @typescript-eslint/interface-name-prefix */ 5 | import { Principal } from '@dfinity/principal'; 6 | 7 | export default interface _SERVICE { 8 | data_of: (token_index: bigint) => Promise; 9 | transfer_to: (to: Principal, tokenIndex: bigint) => Promise; 10 | user_tokens: (user: Principal) => Promise>; 11 | } 12 | 13 | export interface Property { 14 | value: string; 15 | name: string; 16 | } 17 | export interface TokenDesc { 18 | id: bigint; 19 | url: string; 20 | owner: Principal; 21 | desc: string; 22 | name: string; 23 | properties: Array; 24 | } 25 | -------------------------------------------------------------------------------- /src/interfaces/icrc_1.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | import type { ActorMethod } from '@dfinity/agent'; 3 | 4 | export interface Account { 5 | 'owner' : Principal, 6 | 'subaccount' : [] | [Subaccount], 7 | } 8 | export type Duration = bigint; 9 | export type Subaccount = Uint8Array | number[]; 10 | export type Timestamp = bigint; 11 | export interface TransferArgs { 12 | 'to' : Account, 13 | 'fee' : [] | [bigint], 14 | 'memo' : [] | [Uint8Array | number[]], 15 | 'from_subaccount' : [] | [Subaccount], 16 | 'created_at_time' : [] | [Timestamp], 17 | 'amount' : bigint, 18 | } 19 | export type TransferError = { 20 | 'GenericError' : { 'message' : string, 'error_code' : bigint } 21 | } | 22 | { 'TemporarilyUnavailable' : null } | 23 | { 'BadBurn' : { 'min_burn_amount' : bigint } } | 24 | { 'Duplicate' : { 'duplicate_of' : bigint } } | 25 | { 'BadFee' : { 'expected_fee' : bigint } } | 26 | { 'CreatedInFuture' : { 'ledger_time' : Timestamp } } | 27 | { 'TooOld' : null } | 28 | { 'InsufficientFunds' : { 'balance' : bigint } }; 29 | export type Value = { 'Int' : bigint } | 30 | { 'Nat' : bigint } | 31 | { 'Blob' : Uint8Array | number[] } | 32 | { 'Text' : string }; 33 | export default interface _SERVICE { 34 | 'icrc1_balance_of' : ActorMethod<[Account], bigint>, 35 | 'icrc1_decimals' : ActorMethod<[], number>, 36 | 'icrc1_fee' : ActorMethod<[], bigint>, 37 | 'icrc1_metadata' : ActorMethod<[], Array<[string, Value]>>, 38 | 'icrc1_minting_account' : ActorMethod<[], [] | [Account]>, 39 | 'icrc1_name' : ActorMethod<[], string>, 40 | 'icrc1_supported_standards' : ActorMethod< 41 | [], 42 | Array<{ 'url' : string, 'name' : string }> 43 | >, 44 | 'icrc1_symbol' : ActorMethod<[], string>, 45 | 'icrc1_total_supply' : ActorMethod<[], bigint>, 46 | 'icrc1_transfer' : ActorMethod< 47 | [TransferArgs], 48 | { 'Ok' : bigint } | 49 | { 'Err' : TransferError } 50 | >, 51 | } 52 | -------------------------------------------------------------------------------- /src/interfaces/icrc_7.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | import type { ActorMethod } from '@dfinity/agent'; 3 | 4 | export interface Account { 5 | owner: Principal; 6 | subaccount: [] | [Subaccount]; 7 | } 8 | export type Subaccount = Uint8Array | number[]; 9 | export interface TransferArg { 10 | to: Account; 11 | token_id: bigint; 12 | memo: [] | [Uint8Array | number[]]; 13 | from_subaccount: [] | [Uint8Array | number[]]; 14 | created_at_time: [] | [bigint]; 15 | } 16 | export type TransferError = 17 | | { 18 | GenericError: { message: string; error_code: bigint }; 19 | } 20 | | { Duplicate: { duplicate_of: bigint } } 21 | | { NonExistingTokenId: null } 22 | | { Unauthorized: null } 23 | | { CreatedInFuture: { ledger_time: bigint } } 24 | | { InvalidRecipient: null } 25 | | { GenericBatchError: { message: string; error_code: bigint } } 26 | | { TooOld: null }; 27 | export type TransferResult = { Ok: bigint } | { Err: TransferError }; 28 | export type Value = 29 | | { Int: bigint } 30 | | { Map: Array<[string, Value]> } 31 | | { Nat: bigint } 32 | | { Blob: Uint8Array | number[] } 33 | | { Text: string } 34 | | { Array: Array }; 35 | export interface _SERVICE { 36 | icrc7_atomic_batch_transfers: ActorMethod<[], [] | [boolean]>; 37 | icrc7_balance_of: ActorMethod<[Array], Array>; 38 | icrc7_collection_metadata: ActorMethod<[], Array<[string, Value]>>; 39 | icrc7_default_take_value: ActorMethod<[], [] | [bigint]>; 40 | icrc7_description: ActorMethod<[], [] | [string]>; 41 | icrc7_logo: ActorMethod<[], [] | [string]>; 42 | icrc7_max_memo_size: ActorMethod<[], [] | [bigint]>; 43 | icrc7_max_query_batch_size: ActorMethod<[], [] | [bigint]>; 44 | icrc7_max_take_value: ActorMethod<[], [] | [bigint]>; 45 | icrc7_max_update_batch_size: ActorMethod<[], [] | [bigint]>; 46 | icrc7_name: ActorMethod<[], string>; 47 | icrc7_owner_of: ActorMethod<[Array], Array<[] | [Account]>>; 48 | icrc7_permitted_drift: ActorMethod<[], [] | [bigint]>; 49 | icrc7_supply_cap: ActorMethod<[], [] | [bigint]>; 50 | icrc7_symbol: ActorMethod<[], string>; 51 | icrc7_token_metadata: ActorMethod< 52 | [Array], 53 | Array<[] | [Array<[string, Value]>]> 54 | >; 55 | icrc7_tokens: ActorMethod<[[] | [bigint], [] | [bigint]], Array>; 56 | icrc7_tokens_of: ActorMethod< 57 | [Account, [] | [bigint], [] | [bigint]], 58 | Array 59 | >; 60 | icrc7_total_supply: ActorMethod<[], bigint>; 61 | icrc7_transfer: ActorMethod< 62 | [Array], 63 | Array<[] | [TransferResult]> 64 | >; 65 | icrc7_tx_window: ActorMethod<[], [] | [bigint]>; 66 | } 67 | -------------------------------------------------------------------------------- /src/interfaces/ledger.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/class-name-casing */ 2 | /* eslint-disable camelcase */ 3 | /* eslint-disable @typescript-eslint/camelcase */ 4 | import { Principal } from '@dfinity/principal'; 5 | 6 | export interface AccountBalanceArgs { 7 | account: AccountIdentifier; 8 | } 9 | export type AccountIdentifier = string; 10 | export interface ArchiveOptions { 11 | max_message_size_bytes: [] | [number]; 12 | node_max_memory_size_bytes: [] | [number]; 13 | controller_id: Principal; 14 | } 15 | export type BlockHeight = bigint; 16 | export interface Duration { 17 | secs: bigint; 18 | nanos: number; 19 | } 20 | export interface ICPTs { 21 | e8s: bigint; 22 | } 23 | export interface LedgerCanisterInitPayload { 24 | send_whitelist: Array<[Principal]>; 25 | minting_account: AccountIdentifier; 26 | transaction_window: [] | [Duration]; 27 | max_message_size_bytes: [] | [number]; 28 | archive_options: [] | [ArchiveOptions]; 29 | initial_values: Array<[AccountIdentifier, ICPTs]>; 30 | } 31 | export type Memo = bigint; 32 | export interface NotifyCanisterArgs { 33 | to_subaccount: [] | [SubAccount]; 34 | from_subaccount: [] | [SubAccount]; 35 | to_canister: Principal; 36 | max_fee: ICPTs; 37 | block_height: BlockHeight; 38 | } 39 | export interface SendArgs { 40 | to: AccountIdentifier; 41 | fee: ICPTs; 42 | memo: Memo; 43 | from_subaccount: [] | [SubAccount]; 44 | created_at_time: [] | [TimeStamp]; 45 | amount: ICPTs; 46 | } 47 | export type SubAccount = Array; 48 | export interface TimeStamp { 49 | timestamp_nanos: bigint; 50 | } 51 | export interface Transaction { 52 | memo: Memo; 53 | created_at: BlockHeight; 54 | transfer: Transfer; 55 | } 56 | export type Transfer = 57 | | { 58 | Burn: { from: AccountIdentifier; amount: ICPTs }; 59 | } 60 | | { Mint: { to: AccountIdentifier; amount: ICPTs } } 61 | | { 62 | Send: { 63 | to: AccountIdentifier; 64 | from: AccountIdentifier; 65 | amount: ICPTs; 66 | }; 67 | }; 68 | export default interface _SERVICE { 69 | account_balance_dfx: (arg_0: AccountBalanceArgs) => Promise; 70 | notify_dfx: (arg_0: NotifyCanisterArgs) => Promise; 71 | send_dfx: (arg_0: SendArgs) => Promise; 72 | } 73 | -------------------------------------------------------------------------------- /src/interfaces/nft.ts: -------------------------------------------------------------------------------- 1 | import { Principal } from '@dfinity/principal'; 2 | import DepartureLabs from '../standard_wrappers/nft_standards/departure_labs'; 3 | import DIP721 from '../standard_wrappers/nft_standards/dip_721'; 4 | import EXT from '../standard_wrappers/nft_standards/ext'; 5 | import CCC from '../standard_wrappers/nft_standards/ccc'; 6 | import ICPunks from '../standard_wrappers/nft_standards/ic_punks'; 7 | import NFTOrigyn from '../standard_wrappers/nft_standards/nft_origyn'; 8 | import ICRC7 from '../standard_wrappers/nft_standards/icrc_7'; 9 | 10 | export type NFTStandards = 11 | | typeof EXT 12 | | typeof ICPunks 13 | | typeof DepartureLabs 14 | | typeof NFTOrigyn 15 | | typeof DIP721 16 | | typeof CCC 17 | | typeof ICRC7; 18 | 19 | export interface DABCollection { 20 | icon: string; 21 | name: string; 22 | description: string; 23 | principal_id: Principal; 24 | standard: string; 25 | } 26 | 27 | export interface NFTCollection { 28 | name: string; 29 | canisterId: string; 30 | standard: string; 31 | tokens: NFTDetails[]; 32 | icon?: string; 33 | description?: string; 34 | } 35 | 36 | export interface NFTDetails { 37 | index: idT; 38 | canister: string; 39 | id?: string; 40 | name?: string; 41 | url: string; 42 | metadata: any; 43 | standard: string; 44 | collection?: string; 45 | owner?: string; 46 | operator?: string; 47 | } 48 | -------------------------------------------------------------------------------- /src/interfaces/token.ts: -------------------------------------------------------------------------------- 1 | import { Principal } from '@dfinity/principal'; 2 | import { TokenMetaData as ExtMetadata } from './ext'; 3 | import { Metadata as Dip20Metadata } from './dip_20'; 4 | 5 | export interface Token { 6 | logo: string; 7 | name: string; 8 | description: string; 9 | website: string; 10 | principal_id: Principal; 11 | standard: string; 12 | total_supply: [] | [bigint]; 13 | symbol: string; 14 | } 15 | 16 | export interface DRC2OMetadata { 17 | symbol: string; 18 | decimals: number; 19 | fee: bigint; 20 | name: string; 21 | logo?: string; 22 | totalSupply: bigint; 23 | } 24 | 25 | export type TokenMetadata = ExtMetadata | Dip20Metadata | DRC2OMetadata; 26 | 27 | export interface FungibleMetadata { 28 | fungible: TokenMetadata & { 29 | metadata?: Int8Array[]; 30 | }; 31 | } 32 | 33 | export interface NonFungibleMetadata { 34 | nonfungible: { 35 | metadata: Int8Array[]; 36 | }; 37 | } 38 | export type Metadata = FungibleMetadata | NonFungibleMetadata; 39 | 40 | export { 41 | SendOpts, 42 | SendParams, 43 | SendResponse, 44 | BalanceResponse, 45 | BurnParams, 46 | ApproveResponse, 47 | } from '../standard_wrappers/token_standards/methods'; 48 | export { EventDetail, BurnResult } from './xtc'; 49 | -------------------------------------------------------------------------------- /src/interfaces/wicp.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | export interface Metadata { 3 | 'fee' : bigint, 4 | 'decimals' : number, 5 | 'owner' : Principal, 6 | 'logo' : string, 7 | 'name' : string, 8 | 'totalSupply' : bigint, 9 | 'symbol' : string, 10 | } 11 | export interface TokenInfo { 12 | 'holderNumber' : bigint, 13 | 'deployTime' : bigint, 14 | 'metadata' : Metadata, 15 | 'historySize' : bigint, 16 | 'cycles' : bigint, 17 | 'feeTo' : Principal, 18 | } 19 | export type TxError = { 'InsufficientAllowance' : null } | 20 | { 'InsufficientBalance' : null } | 21 | { 'ErrorOperationStyle' : null } | 22 | { 'Unauthorized' : null } | 23 | { 'LedgerTrap' : null } | 24 | { 'ErrorTo' : null } | 25 | { 'Other' : null } | 26 | { 'BlockUsed' : null } | 27 | { 'AmountTooSmall' : null }; 28 | export type TxReceipt = { 'Ok' : bigint } | 29 | { 'Err' : TxError }; 30 | export default interface _SERVICE { 31 | 'allowance' : (arg_0: Principal, arg_1: Principal) => Promise, 32 | 'approve' : (arg_0: Principal, arg_1: bigint) => Promise, 33 | 'balanceOf' : (arg_0: Principal) => Promise, 34 | 'decimals' : () => Promise, 35 | 'getAllowanceSize' : () => Promise, 36 | 'getHolders' : (arg_0: bigint, arg_1: bigint) => Promise< 37 | Array<[Principal, bigint]> 38 | >, 39 | 'getLogo' : () => Promise, 40 | 'getMetadata' : () => Promise, 41 | 'getTokenInfo' : () => Promise, 42 | 'getUserApprovals' : (arg_0: Principal) => Promise< 43 | Array<[Principal, bigint]> 44 | >, 45 | 'historySize' : () => Promise, 46 | 'mint' : (arg_0: [] | [Array], arg_1: bigint) => Promise, 47 | 'name' : () => Promise, 48 | 'owner' : () => Promise, 49 | 'setFee' : (arg_0: bigint) => Promise, 50 | 'setFeeTo' : (arg_0: Principal) => Promise, 51 | 'setLogo' : (arg_0: string) => Promise, 52 | 'setName' : (arg_0: string) => Promise, 53 | 'setOwner' : (arg_0: Principal) => Promise, 54 | 'symbol' : () => Promise, 55 | 'totalSupply' : () => Promise, 56 | 'transfer' : (arg_0: Principal, arg_1: bigint) => Promise, 57 | 'transferFrom' : ( 58 | arg_0: Principal, 59 | arg_1: Principal, 60 | arg_2: bigint, 61 | ) => Promise, 62 | 'withdraw' : (arg_0: bigint, arg_1: string) => Promise, 63 | } -------------------------------------------------------------------------------- /src/interfaces/xtc.ts: -------------------------------------------------------------------------------- 1 | import type { Principal } from '@dfinity/principal'; 2 | export type BurnError = { 'InsufficientBalance' : null } | 3 | { 'InvalidTokenContract' : null } | 4 | { 'NotSufficientLiquidity' : null }; 5 | export type BurnResult = { 'Ok' : TransactionId } | 6 | { 'Err' : BurnError }; 7 | export type CreateResult = { 'Ok' : { 'canister_id' : Principal } } | 8 | { 'Err' : string }; 9 | export interface Event { 10 | 'fee' : bigint, 11 | 'status' : TransactionStatus, 12 | 'kind' : EventDetail, 13 | 'cycles' : bigint, 14 | 'timestamp' : bigint, 15 | }; 16 | export type EventDetail = { 17 | 'Approve' : { 'to' : Principal, 'from' : Principal } 18 | } | 19 | { 'Burn' : { 'to' : Principal, 'from' : Principal } } | 20 | { 'Mint' : { 'to' : Principal } } | 21 | { 'CanisterCreated' : { 'from' : Principal, 'canister' : Principal } } | 22 | { 23 | 'CanisterCalled' : { 24 | 'from' : Principal, 25 | 'method_name' : string, 26 | 'canister' : Principal, 27 | } 28 | } | 29 | { 'Transfer' : { 'to' : Principal, 'from' : Principal } } | 30 | { 31 | 'TransferFrom' : { 32 | 'to' : Principal, 33 | 'from' : Principal, 34 | 'caller' : Principal, 35 | } 36 | }; 37 | export interface EventsConnection { 38 | 'data' : Array, 39 | 'next_offset' : TransactionId, 40 | 'next_canister_id' : [] | [Principal], 41 | }; 42 | export interface Metadata { 43 | 'fee' : bigint, 44 | 'decimals' : number, 45 | 'owner' : Principal, 46 | 'logo' : string, 47 | 'name' : string, 48 | 'totalSupply' : bigint, 49 | 'symbol' : string, 50 | }; 51 | export type MintError = { 'NotSufficientLiquidity' : null }; 52 | export type MintResult = { 'Ok' : TransactionId } | 53 | { 'Err' : MintError }; 54 | export type Operation = { 'transferFrom' : null } | 55 | { 'burn' : null } | 56 | { 'mint' : null } | 57 | { 'approve' : null } | 58 | { 'canisterCalled' : null } | 59 | { 'transfer' : null } | 60 | { 'canisterCreated' : null }; 61 | export type ResultCall = { 'Ok' : { 'return' : Array } } | 62 | { 'Err' : string }; 63 | export type ResultSend = { 'Ok' : null } | 64 | { 'Err' : string }; 65 | export interface Stats { 66 | 'fee' : bigint, 67 | 'transfers_count' : bigint, 68 | 'balance' : bigint, 69 | 'mints_count' : bigint, 70 | 'transfers_from_count' : bigint, 71 | 'canisters_created_count' : bigint, 72 | 'supply' : bigint, 73 | 'burns_count' : bigint, 74 | 'approvals_count' : bigint, 75 | 'proxy_calls_count' : bigint, 76 | 'history_events' : bigint, 77 | }; 78 | export type Time = bigint; 79 | export type TransactionId = bigint; 80 | export type TransactionStatus = { 'FAILED' : null } | 81 | { 'SUCCEEDED' : null }; 82 | export type TxError = { 'InsufficientAllowance' : null } | 83 | { 'InsufficientBalance' : null } | 84 | { 'ErrorOperationStyle' : null } | 85 | { 'Unauthorized' : null } | 86 | { 'LedgerTrap' : null } | 87 | { 'ErrorTo' : null } | 88 | { 'Other' : null } | 89 | { 'BlockUsed' : null } | 90 | { 'AmountTooSmall' : null }; 91 | export type TxReceipt = { 'Ok' : bigint } | 92 | { 'Err' : TxError }; 93 | export interface TxRecord { 94 | 'op' : Operation, 95 | 'to' : Principal, 96 | 'fee' : bigint, 97 | 'status' : TransactionStatus, 98 | 'from' : Principal, 99 | 'timestamp' : Time, 100 | 'caller' : [] | [Principal], 101 | 'index' : bigint, 102 | 'amount' : bigint, 103 | }; 104 | export default interface _SERVICE { 105 | 'allowance' : (arg_0: Principal, arg_1: Principal) => Promise, 106 | 'approve' : (arg_0: Principal, arg_1: bigint) => Promise, 107 | 'balance' : (arg_0: [] | [Principal]) => Promise, 108 | 'balanceOf' : (arg_0: Principal) => Promise, 109 | 'burn' : (arg_0: { 'canister_id' : Principal, 'amount' : bigint }) => Promise< 110 | BurnResult 111 | >, 112 | 'decimals' : () => Promise, 113 | 'events' : (arg_0: { 'offset' : [] | [bigint], 'limit' : number }) => Promise< 114 | EventsConnection 115 | >, 116 | 'getMetadata' : () => Promise, 117 | 'getTransaction' : (arg_0: bigint) => Promise, 118 | 'getTransactions' : (arg_0: bigint, arg_1: bigint) => Promise< 119 | Array 120 | >, 121 | 'get_transaction' : (arg_0: TransactionId) => Promise<[] | [Event]>, 122 | 'halt' : () => Promise, 123 | 'historySize' : () => Promise, 124 | 'logo' : () => Promise, 125 | 'mint' : (arg_0: Principal, arg_1: bigint) => Promise, 126 | 'name' : () => Promise, 127 | 'nameErc20' : () => Promise, 128 | 'stats' : () => Promise, 129 | 'symbol' : () => Promise, 130 | 'totalSupply' : () => Promise, 131 | 'transfer' : (arg_0: Principal, arg_1: bigint) => Promise, 132 | 'transferErc20' : (arg_0: Principal, arg_1: bigint) => Promise, 133 | 'transferFrom' : ( 134 | arg_0: Principal, 135 | arg_1: Principal, 136 | arg_2: bigint, 137 | ) => Promise, 138 | 'wallet_balance' : () => Promise<{ 'amount' : bigint }>, 139 | 'wallet_call' : ( 140 | arg_0: { 141 | 'args' : Array, 142 | 'cycles' : bigint, 143 | 'method_name' : string, 144 | 'canister' : Principal, 145 | }, 146 | ) => Promise, 147 | 'wallet_create_canister' : ( 148 | arg_0: { 'controller' : [] | [Principal], 'cycles' : bigint }, 149 | ) => Promise, 150 | 'wallet_create_wallet' : ( 151 | arg_0: { 'controller' : [] | [Principal], 'cycles' : bigint }, 152 | ) => Promise, 153 | 'wallet_send' : ( 154 | arg_0: { 'canister' : Principal, 'amount' : bigint }, 155 | ) => Promise, 156 | }; 157 | -------------------------------------------------------------------------------- /src/registries/address_book.ts: -------------------------------------------------------------------------------- 1 | import { HttpAgent, Actor } from '@dfinity/agent'; 2 | import AddressBookInterface, { 3 | Response, 4 | Address, 5 | } from '../interfaces/dab_registries/address_book'; 6 | import addressBookIDL from '../idls/dab_registries/address_book.did'; 7 | 8 | const CANISTER_ID = 'i73cm-daaaa-aaaah-abhea-cai'; 9 | 10 | export const getAddressBookActor = (agent: HttpAgent) => { 11 | const actor = Actor.createActor(addressBookIDL, { 12 | agent, 13 | canisterId: CANISTER_ID, 14 | }); 15 | return actor; 16 | }; 17 | 18 | export const getAddresses = async ( 19 | agent: HttpAgent 20 | ): Promise> => { 21 | const actor = getAddressBookActor(agent); 22 | const addresses = await actor.get_all(); 23 | 24 | return addresses.map( 25 | (address) => 26 | ({ 27 | name: address.name, 28 | description: address.description, 29 | emoji: address.emoji, 30 | value: address.value, 31 | } as Address) 32 | ); 33 | }; 34 | 35 | export const addAddress = async ( 36 | agent: HttpAgent, 37 | newAddress: Address 38 | ): Promise => { 39 | const actor = getAddressBookActor(agent); 40 | 41 | const addResponse = await actor.add({ 42 | name: newAddress.name, 43 | description: newAddress.description, 44 | emoji: newAddress.emoji, 45 | value: newAddress.value, 46 | }); 47 | 48 | return addResponse; 49 | }; 50 | 51 | export const removeAddress = async ( 52 | agent: HttpAgent, 53 | addressName: string 54 | ): Promise => { 55 | const actor = getAddressBookActor(agent); 56 | 57 | const removeResponse = await actor.remove(addressName); 58 | 59 | return removeResponse; 60 | }; 61 | 62 | export default { 63 | getAddressBookActor, 64 | getAddresses, 65 | addAddress, 66 | removeAddress, 67 | }; 68 | -------------------------------------------------------------------------------- /src/registries/canister_registry.ts: -------------------------------------------------------------------------------- 1 | import { HttpAgent, ActorSubclass } from '@dfinity/agent'; 2 | 3 | import CanisterRegistryInterface from '../interfaces/dab_registries/canister_registry'; 4 | import IDL from '../idls/dab_registries/canister_registry.did'; 5 | import { IC_HOST } from '../constants'; 6 | import Registry from './standard_registry'; 7 | import { generateActor } from '../utils/actorFactory'; 8 | import { formatMetadata, FormattedMetadata } from '../utils/registry'; 9 | import { Principal } from '@dfinity/principal'; 10 | 11 | const CANISTER_ID = 'curr3-vaaaa-aaaah-abbdq-cai'; 12 | const DEFAULT_AGENT = HttpAgent.createSync({ fetch, host: IC_HOST }); 13 | 14 | interface CanisterMetadata { 15 | url: string; 16 | name: string; 17 | description: string; 18 | version: number; 19 | logo_url: string; 20 | canisterId: string; 21 | } 22 | 23 | const formatBackwardsCompatible = ( 24 | metadata?: FormattedMetadata 25 | ): Omit | undefined => { 26 | if (!metadata) { 27 | return metadata; 28 | } 29 | const { thumbnail, name, description, frontend, details } = metadata; 30 | return { 31 | url: frontend?.[0] || '', 32 | name, 33 | description, 34 | version: Number(details.version), 35 | logo_url: thumbnail, 36 | }; 37 | }; 38 | 39 | export class CanisterRegistry extends Registry { 40 | constructor(agent?: HttpAgent) { 41 | super(CANISTER_ID, agent); 42 | this.actor = generateActor({ 43 | agent: agent || DEFAULT_AGENT, 44 | canisterId: CANISTER_ID, 45 | IDL, 46 | }); 47 | } 48 | public getAll = async (): Promise => { 49 | const canistersMetadata = await ( 50 | this.actor as ActorSubclass 51 | ).get_all(); 52 | return canistersMetadata.map(formatMetadata); 53 | }; 54 | } 55 | 56 | export const getCanisterInfo = async ({ 57 | canisterId, 58 | agent = DEFAULT_AGENT, 59 | }: { 60 | canisterId: Principal | string; 61 | agent?: HttpAgent; 62 | }): Promise => { 63 | const canisterRegistry = new CanisterRegistry(agent); 64 | const canister = await canisterRegistry.get( 65 | Principal.from(canisterId).toString() 66 | ); 67 | const formattedCanister = formatBackwardsCompatible(canister); 68 | return ( 69 | formattedCanister && { 70 | ...formattedCanister, 71 | canisterId: canisterId.toString(), 72 | } 73 | ); 74 | }; 75 | 76 | export const getMultipleCanisterInfo = async ({ 77 | canisterIds, 78 | agent = DEFAULT_AGENT, 79 | }: { 80 | canisterIds: (string | Principal)[]; 81 | agent?: HttpAgent; 82 | }): Promise => { 83 | const canistersMetadata = await Promise.all( 84 | canisterIds.map((canisterId) => getCanisterInfo({ canisterId, agent })) 85 | ); 86 | if (canistersMetadata.length === 0) return []; 87 | return canistersMetadata.filter( 88 | (canister) => !!canister 89 | ) as CanisterMetadata[]; 90 | }; 91 | 92 | export const getAll = async ( 93 | agent?: HttpAgent 94 | ): Promise => { 95 | const allCanisters = await new CanisterRegistry(agent).getAll(); 96 | return allCanisters.map(formatBackwardsCompatible) as CanisterMetadata[]; 97 | }; 98 | 99 | export default { 100 | getCanisterInfo, 101 | getMultipleCanisterInfo, 102 | getAll: (agent: HttpAgent) => new CanisterRegistry(agent).getAll, 103 | }; 104 | -------------------------------------------------------------------------------- /src/registries/index.ts: -------------------------------------------------------------------------------- 1 | export * from './nfts_registry'; 2 | export * from './canister_registry'; 3 | export * from './token_registry'; 4 | export * from './address_book'; -------------------------------------------------------------------------------- /src/registries/nfts_registry.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ActorSubclass, 3 | CreateCertificateOptions, 4 | HttpAgent, 5 | } from '@dfinity/agent'; 6 | import { Principal } from '@dfinity/principal'; 7 | 8 | import NFTRegistryInterface from '../interfaces/dab_registries/nft_registry'; 9 | import { NFTStandards, NFTCollection } from '../interfaces/nft'; 10 | import { DABCollection } from '../interfaces/dab_nfts'; 11 | 12 | import EXT from '../standard_wrappers/nft_standards/ext'; 13 | import ICPunks from '../standard_wrappers/nft_standards/ic_punks'; 14 | import NFTOrigyn from '../standard_wrappers/nft_standards/nft_origyn'; 15 | import DepartureLabs from '../standard_wrappers/nft_standards/departure_labs'; 16 | import NFT from '../standard_wrappers/nft_standards/default'; 17 | import DIP721 from '../standard_wrappers/nft_standards/dip_721'; 18 | 19 | import { NFT as NFTStandard } from '../constants/standards'; 20 | import { IC_HOST, KYASSHU_URL } from '../constants'; 21 | 22 | import IDL from '../idls/dab_registries/nft_registry.did'; 23 | import Registry from './standard_registry'; 24 | import { generateActor } from '../utils/actorFactory'; 25 | import { formatMetadata, FormattedMetadata } from '../utils/registry'; 26 | import CCC from '../standard_wrappers/nft_standards/ccc'; 27 | import ICRC7 from '../standard_wrappers/nft_standards/icrc_7'; 28 | 29 | const CANISTER_ID = 'ctqxp-yyaaa-aaaah-abbda-cai'; 30 | const BATCH_AMOUNT = 5; 31 | 32 | const NFT_STANDARDS: { [key: string]: NFTStandards } = { 33 | [NFTStandard.ext]: EXT, 34 | [NFTStandard.icpunks]: ICPunks, 35 | [NFTStandard.nftOrigyn]: NFTOrigyn, 36 | [NFTStandard.departuresLabs]: DepartureLabs, 37 | [NFTStandard.erc721]: DIP721, 38 | [NFTStandard.dip721]: DIP721, 39 | [NFTStandard.c3]: CCC, 40 | [NFTStandard.icrc7]: ICRC7, 41 | }; 42 | 43 | interface GetBatchedNFTsParams { 44 | principal: Principal; 45 | callback?: (collection: NFTCollection) => void; 46 | batchSize?: number; 47 | onFinish?: (collections: NFTCollection[]) => void; 48 | agent?: HttpAgent; 49 | } 50 | 51 | interface GetNFTActorParams { 52 | canisterId: string; 53 | standard: string; 54 | agent: HttpAgent; 55 | blsVerify?: CreateCertificateOptions['blsVerify']; 56 | } 57 | 58 | interface GetNFTInfoParams { 59 | nftCanisterId: string; 60 | agent?: HttpAgent; 61 | } 62 | 63 | interface GetAllUserNFTsParams { 64 | user: string | Principal; 65 | agent?: HttpAgent; 66 | debug?: boolean; 67 | } 68 | 69 | const DEFAULT_AGENT = HttpAgent.createSync({ fetch, host: IC_HOST }); 70 | 71 | export class NFTRegistry extends Registry { 72 | constructor(agent?: HttpAgent) { 73 | super(CANISTER_ID, agent); 74 | this.actor = generateActor({ 75 | agent: agent || DEFAULT_AGENT, 76 | canisterId: CANISTER_ID, 77 | IDL, 78 | }); 79 | } 80 | public getAll = async (): Promise => { 81 | const canistersMetadata = await ( 82 | this.actor as ActorSubclass 83 | ).get_all(); 84 | return canistersMetadata.map(formatMetadata); 85 | }; 86 | } 87 | 88 | export const getUserCollectionTokens = async ( 89 | collection: DABCollection, 90 | user: Principal, 91 | agent: HttpAgent = DEFAULT_AGENT, 92 | callback: (val?: any) => void = () => {}, 93 | debug = false 94 | ): Promise => { 95 | try { 96 | const NFTActor = getNFTActor({ 97 | canisterId: collection.principal_id.toString(), 98 | agent, 99 | standard: collection.standard, 100 | }); 101 | const details = await NFTActor.getUserTokens(user); 102 | const collectionDetails = { 103 | name: collection.name, 104 | canisterId: collection.principal_id.toString(), 105 | standard: collection.standard, 106 | description: collection.description, 107 | icon: collection.icon, 108 | tokens: details.map((detail) => ({ 109 | ...detail, 110 | collection: collection.name, 111 | })), 112 | }; 113 | if (callback) { 114 | await callback?.(collectionDetails); 115 | } 116 | return collectionDetails; 117 | } catch (e) { 118 | if (debug) { 119 | console.error(e); 120 | } 121 | return { 122 | name: collection.name, 123 | canisterId: collection.principal_id.toString(), 124 | standard: collection.standard, 125 | tokens: [], 126 | }; 127 | } 128 | }; 129 | 130 | const standardNormaliser = ({ standard }: { standard: string }) => { 131 | const userStandardNormalised = standard.toUpperCase(); 132 | const systemStandardNormalised = NFTStandard.dip721.toUpperCase(); 133 | const startsWithDip721 = userStandardNormalised.startsWith( 134 | systemStandardNormalised 135 | ); 136 | const hasSuffix = 137 | userStandardNormalised.split(systemStandardNormalised).filter((v) => v) 138 | .length > 0; 139 | const hasDeprecatedDip721Term = startsWithDip721 && hasSuffix; 140 | 141 | if (hasDeprecatedDip721Term) { 142 | console.warn( 143 | `Warning! Use the term DIP721, not ${standard}, suffixed and others are being deprecated and support will be dropped soon!` 144 | ); 145 | 146 | return NFTStandard.dip721; 147 | } 148 | 149 | return userStandardNormalised; 150 | }; 151 | 152 | export const getNFTActor = ({ 153 | canisterId, 154 | agent, 155 | standard, 156 | blsVerify, 157 | }: GetNFTActorParams): NFT => { 158 | // We might need to override deprecated standards 159 | // which is computed by the standardNormaliser 160 | const standardNormalised = standardNormaliser({ 161 | standard, 162 | }); 163 | 164 | if (!(standardNormalised in NFT_STANDARDS)) { 165 | console.error(`Standard ${standardNormalised} is not implemented`); 166 | 167 | throw new Error(`standard is not supported: ${standardNormalised}`); 168 | } 169 | 170 | return new NFT_STANDARDS[standardNormalised](canisterId, agent, blsVerify); 171 | }; 172 | 173 | export const getNFTInfo = async ({ 174 | nftCanisterId, 175 | agent = DEFAULT_AGENT, 176 | }: GetNFTInfoParams): Promise => { 177 | const registry = new NFTRegistry(agent); 178 | const result = await registry.get(nftCanisterId); 179 | if (!result) return result; 180 | return { 181 | ...result, 182 | icon: result.thumbnail, 183 | standard: result.details.standard as string, 184 | }; 185 | }; 186 | 187 | export const getAllNFTS = async ({ 188 | agent = DEFAULT_AGENT, 189 | }: { agent?: HttpAgent } = {}): Promise => { 190 | const registry = new NFTRegistry(agent); 191 | const allNFTs = await registry.getAll(); 192 | return allNFTs.map((nft) => ({ 193 | ...nft, 194 | icon: nft.thumbnail, 195 | standard: nft.details.standard as string, 196 | })); 197 | }; 198 | 199 | export const getAllUserNFTs = async ({ 200 | user, 201 | agent = DEFAULT_AGENT, 202 | debug = false, 203 | }: GetAllUserNFTsParams): Promise => { 204 | const NFTCollections = await getAllNFTS({ agent }); 205 | const userPrincipal = 206 | user instanceof Principal ? user : Principal.fromText(user); 207 | 208 | const result = await Promise.all( 209 | NFTCollections.map((collection) => 210 | getUserCollectionTokens(collection, userPrincipal, agent, () => {}, debug) 211 | ) 212 | ); 213 | return result.filter((element) => element.tokens.length); 214 | }; 215 | 216 | export const getBatchedNFTs = async ({ 217 | principal, 218 | callback, 219 | batchSize = BATCH_AMOUNT, 220 | onFinish, 221 | agent = DEFAULT_AGENT, 222 | }: GetBatchedNFTsParams) => { 223 | const NFTCollections = await getAllNFTS({ agent }); 224 | let result: NFTCollection[] = []; 225 | 226 | for (let i = 0; i < NFTCollections.length; i += batchSize) { 227 | const batch = NFTCollections.slice(i, i + batchSize); 228 | const batchResult = await Promise.all( 229 | batch.map((collection) => 230 | getUserCollectionTokens(collection, principal, agent, callback) 231 | ) 232 | ); 233 | result = [...result, ...batchResult]; 234 | } 235 | if (onFinish) { 236 | await onFinish?.(result); 237 | } 238 | return result.filter((element) => element?.tokens?.length); 239 | }; 240 | 241 | export const getCachedUserNFTs = async ({ 242 | userPID, 243 | refresh, 244 | }: { 245 | userPID: string; 246 | refresh?: boolean; 247 | }): Promise => { 248 | const url = `${KYASSHU_URL}/dab/user/nfts/${userPID}?refresh=${refresh}`; 249 | const result = await fetch(url); 250 | const response = (await result.json()) as NFTCollection[]; 251 | 252 | return response; 253 | }; 254 | 255 | export default { 256 | getBatchedNFTs, 257 | getNFTActor, 258 | getNFTInfo, 259 | getAllNFTS, 260 | getAllUserNFTs, 261 | getCachedUserNFTs, 262 | }; 263 | -------------------------------------------------------------------------------- /src/registries/standard_registry.ts: -------------------------------------------------------------------------------- 1 | import { Actor, ActorSubclass, HttpAgent } from '@dfinity/agent'; 2 | import { Principal } from '@dfinity/principal'; 3 | import { IC_HOST } from '../constants'; 4 | import RegistryStandardIDL from '../idls/dab_registries/registry_standard.did'; 5 | import RegistryStandard, { 6 | Metadata, 7 | } from '../interfaces/dab_registries/registry_standard'; 8 | import { formatMetadata } from '../utils/registry'; 9 | 10 | const DEFAULT_AGENT = HttpAgent.createSync({ fetch, host: IC_HOST }); 11 | 12 | class Registry { 13 | protected actor: ActorSubclass; // Set as protected so that subclasses can override it 14 | public canisterId: string; 15 | constructor(canisterId, agent = DEFAULT_AGENT) { 16 | this.actor = Actor.createActor(RegistryStandardIDL, { 17 | agent: agent, 18 | canisterId, 19 | }); 20 | this.canisterId = canisterId; 21 | } 22 | 23 | public name = async () => { 24 | return this.actor.name(); 25 | }; 26 | 27 | public add = async (metadata: Metadata) => { 28 | return this.actor.add(metadata ?? []); 29 | }; 30 | 31 | public get = async (principalId: string) => { 32 | const data = await this.actor.get(Principal.fromText(principalId)); 33 | if (data.length === 0) return undefined; 34 | return formatMetadata(data[0]); 35 | }; 36 | 37 | public remove = async (principalId: string) => { 38 | return this.actor.remove(Principal.fromText(principalId)); 39 | }; 40 | } 41 | 42 | export default Registry; 43 | -------------------------------------------------------------------------------- /src/registries/token_registry.ts: -------------------------------------------------------------------------------- 1 | import { 2 | HttpAgent, 3 | ActorSubclass, 4 | CreateCertificateOptions, 5 | } from '@dfinity/agent'; 6 | 7 | import TokenRegistryInterface from '../interfaces/dab_registries/token_registry'; 8 | import IDL from '../idls/dab_registries/token_registry.did'; 9 | 10 | import Registry from './standard_registry'; 11 | import { generateActor } from '../utils/actorFactory'; 12 | import { formatMetadata, FormattedMetadata } from '../utils/registry'; 13 | 14 | import { IC_HOST } from '../constants'; 15 | import { createTokenActor } from '../standard_wrappers/token_standards'; 16 | import { TOKEN } from '../constants/standards'; 17 | import { Token } from '../interfaces/token'; 18 | 19 | const CANISTER_ID = 'b7hhy-tyaaa-aaaah-abbja-cai'; 20 | 21 | const DEFAULT_AGENT = HttpAgent.createSync({ fetch, host: IC_HOST }); 22 | 23 | export const TOKEN_STANDARDS = Object.values(TOKEN); 24 | 25 | interface GetTokenActorParams { 26 | canisterId: string; 27 | standard: string; 28 | agent: HttpAgent; 29 | blsVerify?: CreateCertificateOptions['blsVerify']; 30 | } 31 | 32 | export const getTokenActor = ({ 33 | canisterId, 34 | agent, 35 | standard, 36 | blsVerify, 37 | }: GetTokenActorParams) => { 38 | if (!TOKEN_STANDARDS.includes(standard)) { 39 | console.error(`Standard ${standard} is not implemented`); 40 | throw new Error(`standard is not supported: ${standard}`); 41 | } 42 | return createTokenActor(canisterId, agent, standard, blsVerify); 43 | }; 44 | 45 | export class TokenRegistry extends Registry { 46 | constructor(agent?: HttpAgent) { 47 | super(CANISTER_ID, agent); 48 | this.actor = generateActor({ 49 | agent: agent || DEFAULT_AGENT, 50 | canisterId: CANISTER_ID, 51 | IDL, 52 | }); 53 | } 54 | public getAll = async (): Promise => { 55 | const tokenCanistersMetadata = await ( 56 | this.actor as ActorSubclass 57 | ).get_all(); 58 | return tokenCanistersMetadata.map(formatMetadata); 59 | }; 60 | } 61 | 62 | export const getTokens = async ({ agent = DEFAULT_AGENT } = {}): Promise< 63 | Token[] 64 | > => { 65 | const tokenRegistry = new TokenRegistry(agent); 66 | const tokenCanisters = await tokenRegistry.getAll(); 67 | return tokenCanisters.map((token) => ({ 68 | ...token, 69 | logo: token.thumbnail, 70 | name: token.name, 71 | description: token.description, 72 | website: token.frontend.length ? token.frontend[0] : '', 73 | principal_id: token.principal_id, 74 | standard: token.details.standard as string, 75 | total_supply: [token.details.total_supply as bigint], 76 | symbol: token.details.symbol as string, 77 | })); 78 | }; 79 | 80 | export default { 81 | getTokenActor, 82 | getTokens, 83 | addToken: async ({ agent, tokenInfo }) => 84 | new TokenRegistry(agent).add(tokenInfo), 85 | // editToken: async ({ agent, tokenInfo }) => new TokenRegistry(agent).edit(tokenInfo), 86 | removeToken: async ({ agent, canisterId }) => 87 | new TokenRegistry(agent).remove(canisterId), 88 | }; 89 | -------------------------------------------------------------------------------- /src/standard_wrappers/nft_standards/ccc.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Actor, 3 | ActorSubclass, 4 | CreateCertificateOptions, 5 | HttpAgent, 6 | } from '@dfinity/agent'; 7 | import { Principal } from '@dfinity/principal'; 8 | 9 | import NFT_C3, { 10 | GetTokenResponse, 11 | TokenDetails, 12 | TransferResponse, 13 | } from '../../interfaces/c3'; 14 | import IDL from '../../idls/c3.did'; 15 | import NFT from './default'; 16 | import { NFTCollection, NFTDetails } from '../../interfaces/nft'; 17 | import { NFT as NFTStandard } from '../../constants/standards'; 18 | 19 | export default class CCC extends NFT { 20 | getMetadata(): Promise { 21 | throw new Error('Method not implemented.'); 22 | } 23 | 24 | standard = NFTStandard.c3; 25 | 26 | actor: ActorSubclass; 27 | 28 | constructor( 29 | canisterId: string, 30 | agent: HttpAgent, 31 | blsVerify?: CreateCertificateOptions['blsVerify'] 32 | ) { 33 | super(canisterId, agent); 34 | 35 | this.actor = Actor.createActor(IDL, { 36 | agent, 37 | canisterId, 38 | blsVerify, 39 | }); 40 | } 41 | 42 | async getUserTokens(principal: Principal): Promise { 43 | const tokensIndexes = await this.actor.getAllNFT(principal); 44 | const tokensData = await Promise.all( 45 | tokensIndexes.map(async (item) => { 46 | const tokenIndex = item[0]; 47 | const principal = item[1]; 48 | const userTokensResult = await this.actor.getTokenById(tokenIndex); 49 | if ('err' in userTokensResult) 50 | throw new Error(Object.keys(userTokensResult.err)[0]); 51 | return { detail: userTokensResult.ok, principal }; 52 | }) 53 | ); 54 | return tokensData.map((token) => 55 | this.serializeTokenData(token.detail, token.principal) 56 | ); 57 | } 58 | 59 | async transfer(to: Principal, tokenIndex: number): Promise { 60 | const from = await this.agent.getPrincipal(); 61 | const transferResult: TransferResponse = await this.actor.transferFrom( 62 | from, 63 | to, 64 | BigInt(tokenIndex) 65 | ); 66 | if ('err' in transferResult) 67 | throw new Error(Object.keys(transferResult.err)[0]); 68 | } 69 | 70 | async details(tokenIndex: number): Promise { 71 | const tokenData = await this.actor.getTokenById(BigInt(tokenIndex)); 72 | if ('err' in tokenData) throw new Error(Object.keys(tokenData.err)[0]); 73 | const prinId = await this.actor.getNftStoreCIDByIndex(BigInt(tokenIndex)); 74 | if (!prinId) throw new Error('Error tokenIndex'); 75 | return this.serializeTokenData(tokenData.ok, prinId); 76 | } 77 | 78 | private serializeTokenData = ( 79 | tokenData: TokenDetails, 80 | prinId: Principal 81 | ): NFTDetails => { 82 | return { 83 | index: BigInt(tokenData.id), 84 | canister: this.canisterId, 85 | url: `https://${prinId.toText()}.raw.icp0.io/token/${tokenData.id}`, 86 | name: `${tokenData.id}`, 87 | metadata: tokenData, 88 | standard: this.standard, 89 | }; 90 | }; 91 | } 92 | -------------------------------------------------------------------------------- /src/standard_wrappers/nft_standards/default.ts: -------------------------------------------------------------------------------- 1 | import { HttpAgent } from '@dfinity/agent'; 2 | import { Principal } from '@dfinity/principal'; 3 | 4 | import { NFTCollection, NFTDetails } from '../../interfaces/nft'; 5 | 6 | export default abstract class NFT { 7 | abstract standard: string; 8 | 9 | agent: HttpAgent; 10 | 11 | canisterId: string; 12 | 13 | constructor(canisterId: string, agent: HttpAgent) { 14 | this.agent = agent; 15 | this.canisterId = canisterId; 16 | } 17 | 18 | abstract getUserTokens(principal: Principal): Promise[]>; 19 | 20 | abstract transfer(principal: Principal, tokenIndex: Tid): Promise; 21 | 22 | abstract getMetadata(): Promise; 23 | 24 | abstract details(tokenIndex: Tid): Promise>; 25 | } 26 | -------------------------------------------------------------------------------- /src/standard_wrappers/nft_standards/departure_labs.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Actor, 3 | ActorSubclass, 4 | CreateCertificateOptions, 5 | HttpAgent, 6 | } from '@dfinity/agent'; 7 | import { Principal } from '@dfinity/principal'; 8 | 9 | import NFT_DEPARTURE_LABS, { Metadata } from '../../interfaces/departure_labs'; 10 | import IDL from '../../idls/departure_labs.did'; 11 | import NFT from './default'; 12 | import { NFTCollection, NFTDetails } from '../../interfaces/nft'; 13 | import { NFT as NFTStandard } from '../../constants/standards'; 14 | 15 | export default class DepartureLabs extends NFT { 16 | standard = NFTStandard.departuresLabs; 17 | 18 | actor: ActorSubclass; 19 | 20 | constructor( 21 | canisterId: string, 22 | agent: HttpAgent, 23 | blsVerify?: CreateCertificateOptions['blsVerify'] 24 | ) { 25 | super(canisterId, agent); 26 | 27 | this.actor = Actor.createActor(IDL, { 28 | agent, 29 | canisterId, 30 | blsVerify, 31 | }); 32 | } 33 | 34 | getMetadata(): Promise { 35 | throw new Error('Method not implemented.'); 36 | } 37 | async getUserTokens(principal: Principal): Promise { 38 | const tokensIndexes = await this.actor.balanceOf(principal); 39 | const tokensData = await Promise.all( 40 | tokensIndexes.map(async (tokenIndex) => { 41 | const userTokensResult = await this.actor.tokenMetadataByIndex( 42 | tokenIndex 43 | ); 44 | if ('err' in userTokensResult) 45 | throw new Error(Object.keys(userTokensResult.err)[0]); 46 | 47 | return userTokensResult.ok; 48 | }) 49 | ); 50 | 51 | return tokensData.map((token) => this.serializeTokenData(token)); 52 | } 53 | 54 | async transfer(to: Principal, tokenIndex: number): Promise { 55 | const transferResult = await this.actor.transfer( 56 | to, 57 | tokenIndex.toString(10) 58 | ); 59 | if ('err' in transferResult) 60 | throw new Error(Object.keys(transferResult.err)[0]); 61 | } 62 | 63 | async details(tokenIndex: number): Promise { 64 | const tokenData = await this.actor.tokenMetadataByIndex( 65 | tokenIndex.toString(10) 66 | ); 67 | 68 | if ('err' in tokenData) throw new Error(Object.keys(tokenData.err)[0]); 69 | 70 | return this.serializeTokenData(tokenData.ok); 71 | } 72 | 73 | private serializeTokenData = (tokenData: Metadata): NFTDetails => ({ 74 | index: BigInt(tokenData.id), 75 | canister: this.canisterId, 76 | url: `https://${this.canisterId}.raw.icp0.io/nft/${tokenData.id}`, 77 | metadata: tokenData, 78 | standard: this.standard, 79 | }); 80 | } 81 | -------------------------------------------------------------------------------- /src/standard_wrappers/nft_standards/dip_721.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Actor, 3 | ActorSubclass, 4 | CreateCertificateOptions, 5 | HttpAgent, 6 | } from '@dfinity/agent'; 7 | import { Principal } from '@dfinity/principal'; 8 | 9 | import { NFTCollection, NFTDetails } from '../../interfaces/nft'; 10 | import Interface, { 11 | TokenMetadata, 12 | GenericValue, 13 | } from '../../interfaces/dip_721'; 14 | import IDL from '../../idls/dip_721.did'; 15 | import NFT from './default'; 16 | import { NFT as NFTStandard } from '../../constants/standards'; 17 | 18 | interface Property { 19 | name: string; 20 | value: string; 21 | } 22 | 23 | interface MetadataKeyVal { 24 | key: string; 25 | val: GenericValue; 26 | } 27 | 28 | interface Metadata { 29 | [key: string]: 30 | | { value: MetadataKeyVal; purpose: string } 31 | | Array 32 | | string; 33 | properties: Array; 34 | } 35 | 36 | const extractMetadataValue = (metadata: any) => { 37 | const metadataKey = Object.keys(metadata)[0]; 38 | const value = metadata[metadataKey]; 39 | return typeof value === 'object' ? JSON.stringify(value) : value; 40 | }; 41 | 42 | const deprecationWarningForDip721LegacyRequests = ({ 43 | methodName, 44 | }: { 45 | methodName: string; 46 | }) => 47 | `Oops! An attempt to ${methodName} failed, a fallback to legacy will be used. Legacy DIP721 contract support will be dropped soon, the contract should be updated`; 48 | 49 | export default class ERC721 extends NFT { 50 | standard = NFTStandard.dip721; 51 | 52 | actor: ActorSubclass; 53 | 54 | constructor( 55 | canisterId: string, 56 | agent: HttpAgent, 57 | blsVerify?: CreateCertificateOptions['blsVerify'] 58 | ) { 59 | super(canisterId, agent); 60 | 61 | this.actor = Actor.createActor(IDL, { 62 | agent, 63 | canisterId, 64 | blsVerify, 65 | }); 66 | } 67 | 68 | backwardsCompatibleGuard(legacyMethod: string, newMethod: string) { 69 | return async (params: Array = []) => { 70 | let res; 71 | try { 72 | res = await this.actor[newMethod](...params); 73 | } catch (err) { 74 | deprecationWarningForDip721LegacyRequests({ 75 | methodName: newMethod, 76 | }); 77 | res = await this.actor[legacyMethod](...params); 78 | } 79 | return res; 80 | }; 81 | } 82 | 83 | async getUserTokens(principal: Principal): Promise { 84 | const guardedGetUserTokens = this.backwardsCompatibleGuard( 85 | 'ownerTokenMetadata', 86 | 'dip721_owner_token_metadata' 87 | ); 88 | const userTokensResult = await guardedGetUserTokens([principal]); 89 | const tokens: Array = userTokensResult['Ok'] || []; 90 | 91 | if (!tokens.length) return []; 92 | 93 | const formattedTokenData = tokens 94 | .map((token) => { 95 | const tokenIndex = token.token_identifier; 96 | const formatedMetadata = this.formatMetadata(token); 97 | 98 | if (!formatedMetadata) return; 99 | 100 | const operator = token.operator?.[0]?.toText(); 101 | 102 | return this.serializeTokenData( 103 | formatedMetadata, 104 | tokenIndex, 105 | principal.toText(), 106 | operator 107 | ); 108 | }) 109 | .filter((token) => token) as NFTDetails[]; 110 | 111 | return formattedTokenData; 112 | } 113 | 114 | async transfer(to: Principal, tokenIndex: number): Promise { 115 | const guardedTransfer = this.backwardsCompatibleGuard( 116 | 'transfer', 117 | 'dip721_transfer' 118 | ); 119 | const transferResult = await guardedTransfer([to, BigInt(tokenIndex)]); 120 | 121 | if ('Err' in transferResult) 122 | throw new Error( 123 | `${Object.keys(transferResult.Err)[0]}: ${ 124 | Object.values(transferResult.Err)[0] 125 | }` 126 | ); 127 | } 128 | 129 | async details(tokenIndex: number): Promise { 130 | const guardedDetails = this.backwardsCompatibleGuard( 131 | 'tokenMetadata', 132 | 'dip721_token_metadata' 133 | ); 134 | const metadataResult = await guardedDetails([BigInt(tokenIndex)]); 135 | 136 | if ('Err' in metadataResult) 137 | throw new Error( 138 | `${Object.keys(metadataResult.Err)[0]}: ${ 139 | Object.values(metadataResult.Err)[0] 140 | }` 141 | ); 142 | const metadata = metadataResult?.Ok; 143 | const formatedMetadata = this.formatMetadata(metadata); 144 | const owner = metadata?.owner?.[0]?.toText?.(); 145 | const operator = metadata?.operator?.[0]?.toText?.(); 146 | 147 | return this.serializeTokenData( 148 | formatedMetadata, 149 | tokenIndex, 150 | owner, 151 | operator 152 | ); 153 | } 154 | 155 | async getMetadata(): Promise { 156 | const guardedGetMetadata = this.backwardsCompatibleGuard( 157 | 'metadata', 158 | 'dip721_get_metadata' 159 | ); 160 | const metadata = await guardedGetMetadata(); 161 | 162 | return { 163 | icon: metadata?.logo[0], 164 | name: metadata?.name?.[0] || '', 165 | standard: this.standard, 166 | canisterId: this.canisterId, 167 | tokens: [], 168 | description: '', 169 | }; 170 | } 171 | 172 | private serializeTokenData( 173 | metadata: any, 174 | tokenIndex: number | bigint, 175 | owner: string | undefined, 176 | operator: string | undefined 177 | ): NFTDetails { 178 | return { 179 | index: BigInt(tokenIndex), 180 | canister: this.canisterId, 181 | metadata, 182 | owner, 183 | url: metadata?.location?.value?.TextContent || '', 184 | standard: this.standard, 185 | operator, 186 | }; 187 | } 188 | 189 | private formatMetadata(metadata: TokenMetadata): Metadata | undefined { 190 | const metadataResult = { properties: new Array() }; 191 | 192 | if (!metadata?.properties || !Array.isArray(metadata.properties)) { 193 | console.warn( 194 | `Oops! Failed to format the metadata properties for token, field is missing or invalid. See ${JSON.stringify( 195 | metadata 196 | )}` 197 | ); 198 | console.log(metadata); 199 | 200 | return; 201 | } 202 | 203 | metadata.properties.forEach((prop) => { 204 | const propertyName = prop[0]; 205 | metadataResult[propertyName] = { value: prop[1] }; 206 | 207 | const value = (() => { 208 | try { 209 | return extractMetadataValue(prop[1]); 210 | } catch (err) { 211 | console.warn( 212 | `Oops! Failed to extract metadata value for property ${propertyName}, is that a valid key value pair?` 213 | ); 214 | console.error(err); 215 | } 216 | })(); 217 | 218 | metadataResult.properties = [ 219 | ...metadataResult.properties, 220 | { name: prop[0], value }, 221 | ]; 222 | }); 223 | 224 | // Filter out reserved props from the unique traits 225 | metadataResult.properties = metadataResult.properties.filter( 226 | ({ name }) => 227 | !['location', 'thumbnail', 'contentHash', 'contentType'].includes(name) 228 | ); 229 | return metadataResult; 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /src/standard_wrappers/nft_standards/ext.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Actor, 3 | ActorSubclass, 4 | CreateCertificateOptions, 5 | HttpAgent, 6 | } from '@dfinity/agent'; 7 | import { Principal } from '@dfinity/principal'; 8 | 9 | import { NFTCollection, NFTDetails } from '../../interfaces/nft'; 10 | import NTF_EXT from '../../interfaces/ext'; 11 | import IDL from '../../idls/ext.did'; 12 | import NFT from './default'; 13 | import { getAccountId } from '../../utils/account'; 14 | import { to32bits } from '../../utils/number'; 15 | import { NFT_CANISTERS } from '../../constants/canisters'; 16 | import { NFT as NFTStandard } from '../../constants/standards'; 17 | 18 | const getTokenIdentifier = (canister: string, index: number): string => { 19 | const padding = Buffer.from('\x0Atid'); 20 | const array = new Uint8Array([ 21 | ...padding, 22 | ...Principal.fromText(canister).toUint8Array(), 23 | ...to32bits(index), 24 | ]); 25 | return Principal.fromUint8Array(array).toText(); 26 | }; 27 | 28 | const extImageUrl = (canisterId, index, tokenIdentifier) => 29 | ({ 30 | [NFT_CANISTERS.WRAPPED_PUNKS]: `https://${NFT_CANISTERS.IC_PUNKS}.raw.icp0.io/Token/${index}`, 31 | [NFT_CANISTERS.WRAPPED_DRIP]: `https://${NFT_CANISTERS.IC_DRIP}.raw.icp0.io?tokenId=${index}`, 32 | }[canisterId] || 33 | `https://${canisterId}.raw.icp0.io/?type=thumbnail&tokenid=${tokenIdentifier}`); 34 | 35 | export default class EXT extends NFT { 36 | standard = NFTStandard.ext; 37 | 38 | actor: ActorSubclass; 39 | 40 | constructor( 41 | canisterId: string, 42 | agent: HttpAgent, 43 | blsVerify?: CreateCertificateOptions['blsVerify'] 44 | ) { 45 | super(canisterId, agent); 46 | 47 | this.actor = Actor.createActor(IDL, { 48 | agent, 49 | canisterId, 50 | blsVerify, 51 | }); 52 | } 53 | 54 | async getUserTokens(principal: Principal): Promise { 55 | const accountId = getAccountId(principal); 56 | const userTokensResult = await this.actor.tokens_ext(accountId); 57 | if ('err' in userTokensResult) 58 | throw new Error( 59 | `${Object.keys(userTokensResult.err)[0]}: ${ 60 | Object.values(userTokensResult.err)[0] 61 | }` 62 | ); 63 | 64 | const tokens = userTokensResult.ok || []; 65 | 66 | return tokens.map((token) => { 67 | const metadata = token[2]; 68 | const tokenIndex = token[0]; 69 | 70 | return this.serializeTokenData( 71 | metadata, 72 | getTokenIdentifier(this.canisterId, tokenIndex), 73 | tokenIndex 74 | ); 75 | }); 76 | } 77 | 78 | getMetadata(): Promise { 79 | throw new Error('Method not implemented.'); 80 | } 81 | 82 | async transfer(to: Principal, tokenIndex: number): Promise { 83 | const tokenIdentifier = getTokenIdentifier(this.canisterId, tokenIndex); 84 | const from = await this.agent.getPrincipal(); 85 | const dummyMemmo = new Array(32).fill(0); 86 | 87 | const transferResult = await this.actor.transfer({ 88 | to: { principal: to }, 89 | from: { principal: from }, 90 | token: tokenIdentifier, 91 | amount: BigInt(1), 92 | memo: dummyMemmo, 93 | notify: false, 94 | subaccount: [], 95 | fee: BigInt(0), 96 | }); 97 | if ('err' in transferResult) 98 | throw new Error( 99 | `${Object.keys(transferResult.err)[0]}: ${ 100 | Object.values(transferResult.err)[0] 101 | }` 102 | ); 103 | } 104 | 105 | async details(tokenIndex: number): Promise { 106 | const tokenIdentifier = getTokenIdentifier(this.canisterId, tokenIndex); 107 | const metadataResult = await this.actor.metadata(tokenIdentifier); 108 | 109 | if ('err' in metadataResult) 110 | throw new Error( 111 | `${Object.keys(metadataResult.err)[0]}: ${ 112 | Object.values(metadataResult.err)[0] 113 | }` 114 | ); 115 | 116 | const { metadata = {} } = 117 | 'nonfungible' in metadataResult.ok ? metadataResult.ok.nonfungible : {}; 118 | 119 | return this.serializeTokenData(metadata, tokenIdentifier, tokenIndex); 120 | } 121 | 122 | private serializeTokenData( 123 | metadata: any, 124 | tokenIdentifier: string, 125 | tokenIndex: number 126 | ): NFTDetails { 127 | return { 128 | id: tokenIdentifier, 129 | index: BigInt(tokenIndex), 130 | canister: this.canisterId, 131 | metadata: metadata.length ? metadata[0] : undefined, 132 | url: extImageUrl(this.canisterId, tokenIndex, tokenIdentifier), 133 | standard: this.standard, 134 | }; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/standard_wrappers/nft_standards/ic_punks.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Actor, 3 | ActorSubclass, 4 | CreateCertificateOptions, 5 | HttpAgent, 6 | } from '@dfinity/agent'; 7 | import { Principal } from '@dfinity/principal'; 8 | 9 | import NFT_ICPUNKS, { TokenDesc } from '../../interfaces/icpunks'; 10 | import IDL from '../../idls/icpunks.did'; 11 | import NFT from './default'; 12 | import { NFTCollection, NFTDetails } from '../../interfaces/nft'; 13 | import { NFT_CANISTERS } from '../../constants/canisters'; 14 | import { NFT as NFTStandard } from '../../constants/standards'; 15 | 16 | const getICPBunnyCanisterId = (index) => 17 | NFT_CANISTERS.ICP_BUNNY_STORAGE[index % 10]; 18 | 19 | const imageUrl = (canisterId: string, index: number, tokenDataUrl: string) => 20 | ({ 21 | [NFT_CANISTERS.ICP_BUNNY_MAIN]: `https://${getICPBunnyCanisterId( 22 | index 23 | )}.raw.icp0.io/Token/${index}`, 24 | }[canisterId] || `https://${canisterId}.raw.icp0.io${tokenDataUrl}`); 25 | export default class ICPUNKS extends NFT { 26 | getMetadata(): Promise { 27 | throw new Error('Method not implemented.'); 28 | } 29 | standard = NFTStandard.icpunks; 30 | 31 | actor: ActorSubclass; 32 | 33 | constructor( 34 | canisterId: string, 35 | agent: HttpAgent, 36 | blsVerify?: CreateCertificateOptions['blsVerify'] 37 | ) { 38 | super(canisterId, agent); 39 | 40 | this.actor = Actor.createActor(IDL, { 41 | agent, 42 | canisterId, 43 | blsVerify, 44 | }); 45 | } 46 | 47 | async getUserTokens(principal: Principal): Promise { 48 | const tokensIndexes = await this.actor.user_tokens(principal); 49 | 50 | const tokensData = await Promise.all( 51 | tokensIndexes.map((tokenIndex) => this.actor.data_of(tokenIndex)) 52 | ); 53 | 54 | return tokensData.map((token) => this.serializeTokenData(token)); 55 | } 56 | 57 | async transfer(to: Principal, tokenIndex: number): Promise { 58 | const success = await this.actor.transfer_to(to, BigInt(tokenIndex)); 59 | if (!success) { 60 | throw new Error('Error transfering token'); 61 | } 62 | } 63 | 64 | async details(tokenIndex: number): Promise { 65 | const tokenData = await this.actor.data_of(BigInt(tokenIndex)); 66 | 67 | return this.serializeTokenData(tokenData); 68 | } 69 | 70 | private serializeTokenData = (tokenData: TokenDesc): NFTDetails => ({ 71 | index: BigInt(tokenData.id), 72 | canister: this.canisterId, 73 | url: imageUrl( 74 | this.canisterId, 75 | Number.parseInt(tokenData.id.toString(), 10), 76 | tokenData.url 77 | ), 78 | name: tokenData.name, 79 | metadata: tokenData, 80 | standard: this.standard, 81 | }); 82 | } 83 | -------------------------------------------------------------------------------- /src/standard_wrappers/nft_standards/icrc_7.ts: -------------------------------------------------------------------------------- 1 | import { Principal } from '@dfinity/principal'; 2 | import { NFTDetails, NFTCollection } from '../../interfaces/nft'; 3 | 4 | import { _SERVICE as NFT_ICRC7, Value } from '../../interfaces/icrc_7'; 5 | import { idlFactory } from '../../idls/icrc_7.did'; 6 | 7 | import NFT from './default'; 8 | import { NFT as NFTStandard } from '../../constants/standards'; 9 | import { 10 | Actor, 11 | ActorSubclass, 12 | CreateCertificateOptions, 13 | HttpAgent, 14 | } from '@dfinity/agent'; 15 | 16 | const PAGE_SIZE = 1; 17 | 18 | export default class ICRC7 extends NFT { 19 | standard = NFTStandard.icrc7; 20 | actor: ActorSubclass; 21 | 22 | constructor( 23 | canisterId: string, 24 | agent: HttpAgent, 25 | blsVerify?: CreateCertificateOptions['blsVerify'] 26 | ) { 27 | super(canisterId, agent); 28 | 29 | this.actor = Actor.createActor(idlFactory, { 30 | agent, 31 | canisterId, 32 | blsVerify, 33 | }); 34 | } 35 | 36 | findMetada(key: string, metadata: [string, Value][]) { 37 | return (metadata.find((meta) => meta[0] === key)?.[1] as { Text: string }) 38 | ?.Text; 39 | } 40 | 41 | mapToken(id: bigint, metadata: [string, Value][], owner: string) { 42 | return { 43 | index: id, 44 | canister: this.canisterId, 45 | name: this.findMetada('Name', metadata), 46 | url: this.findMetada('logo', metadata), 47 | standard: 'ICRC7', 48 | owner, 49 | metadata, 50 | }; 51 | } 52 | 53 | async getUserTokens(principal: Principal): Promise[]> { 54 | let ids: bigint[] = []; 55 | let shouldLoad = true; 56 | 57 | while (shouldLoad) { 58 | const newIds = await this.actor.icrc7_tokens_of( 59 | { owner: principal, subaccount: [] }, 60 | ids.length === 0 ? [] : [ids[ids.length - 1]], 61 | [BigInt(PAGE_SIZE)] 62 | ); 63 | 64 | const filtered = newIds.filter((id) => !ids.includes(id)); 65 | 66 | ids = [...ids, ...filtered]; 67 | shouldLoad = filtered.length >= PAGE_SIZE; 68 | } 69 | 70 | const metadata = await this.actor.icrc7_token_metadata(ids); 71 | const response = metadata[0] as [string, Value][][]; 72 | 73 | return response.map((metadata, index) => 74 | this.mapToken(ids[index], metadata, principal.toString()) 75 | ); 76 | } 77 | 78 | async transfer(principal: Principal, tokenIndex: number): Promise { 79 | const result = await this.actor.icrc7_transfer([ 80 | { 81 | to: { 82 | owner: principal, 83 | subaccount: [], 84 | }, 85 | token_id: BigInt(tokenIndex), 86 | memo: [], 87 | from_subaccount: [], 88 | created_at_time: [], 89 | }, 90 | ])[0]; 91 | 92 | if ('Err' in result[0]) { 93 | throw new Error(Object.keys(result[0].Err)[0]); 94 | } 95 | } 96 | 97 | async getMetadata(): Promise { 98 | throw new Error('Method not implemented.'); 99 | } 100 | 101 | async details(tokenIndex: number): Promise> { 102 | const details = await this.actor.icrc7_token_metadata([BigInt(tokenIndex)]); 103 | const owner = await this.actor.icrc7_owner_of([BigInt(tokenIndex)]); 104 | 105 | if (details.length === 0) return Promise.reject('No metadata available'); 106 | 107 | return this.mapToken( 108 | BigInt(tokenIndex), 109 | details[0][0]!, 110 | owner[0][0]?.owner?.toString() || '' 111 | ); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/standard_wrappers/nft_standards/nft_origyn.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Actor, 3 | ActorSubclass, 4 | CreateCertificateOptions, 5 | HttpAgent, 6 | } from '@dfinity/agent'; 7 | import { Principal } from '@dfinity/principal'; 8 | 9 | import NFT_Origyn, { Result_5 } from '../../interfaces/nft_origyn'; 10 | import IDL from '../../idls/nft_origyn.did'; 11 | import NFT from './default'; 12 | import { NFTDetails, NFTCollection } from '../../interfaces/nft'; 13 | import { NFT as NFTStandard } from '../../constants/standards'; 14 | 15 | export default class NFTOrigyn extends NFT { 16 | standard = NFTStandard.nftOrigyn; 17 | 18 | actor: ActorSubclass; 19 | 20 | constructor( 21 | canisterId: string, 22 | agent: HttpAgent, 23 | blsVerify?: CreateCertificateOptions['blsVerify'] 24 | ) { 25 | super(canisterId, agent); 26 | 27 | this.actor = Actor.createActor(IDL, { 28 | agent, 29 | canisterId, 30 | blsVerify, 31 | }); 32 | } 33 | 34 | async getUserTokens(principal: Principal): Promise[]> { 35 | const tokensIndexes = await this.actor.balance_of_nft_origyn({ principal }); 36 | if ('err' in tokensIndexes) { 37 | throw new Error(Object.keys(tokensIndexes.err)[0]); 38 | } 39 | const tokensData = await Promise.all( 40 | tokensIndexes.ok.nfts.map(async (item) => { 41 | const userTokensResult = await this.actor.nft_origyn(item); 42 | if ('err' in userTokensResult) 43 | throw new Error(Object.keys(userTokensResult.err)[0]); 44 | return { detail: userTokensResult, principal }; 45 | }) 46 | ); 47 | return tokensData.map((token) => this.serializeTokenData(token.detail)); 48 | } 49 | 50 | getMetadata(): Promise { 51 | throw new Error('Method not implemented.'); 52 | } 53 | async transfer(to: Principal, tokenIndex: string): Promise { 54 | const from = await this.agent.getPrincipal(); 55 | const balance = await this.actor.balance_of_nft_origyn({ principal: to }); 56 | if ('err' in balance) { 57 | throw new Error(Object.keys(balance.err)[0]); 58 | } 59 | const escrow = balance.ok.escrow.find( 60 | ({ token_id }) => token_id === tokenIndex 61 | ); 62 | if (!escrow) { 63 | // This error occurs if no pending escrows for this NFT exist (see market_transfer_nft_origyn comment) 64 | throw new Error('No pending escrows for transfer.'); 65 | } 66 | // market transfer relies on escrow(payment) existing for NFT, to only be able to sell NFTs directly thru canister 67 | // there is owner_transfer_nft_origyn which take "from" and "to" params, but that method is not preferred 68 | const transferResult = await this.actor.market_transfer_nft_origyn({ 69 | token_id: tokenIndex, 70 | sales_config: { 71 | pricing: { instant: null }, 72 | escrow_receipt: [escrow], 73 | }, 74 | }); 75 | if ('err' in transferResult) 76 | throw new Error(Object.keys(transferResult.err)[0]); 77 | } 78 | 79 | async details(tokenIndex: string): Promise> { 80 | const tokenData = await this.actor.nft_origyn(tokenIndex); 81 | return this.serializeTokenData(tokenData); 82 | } 83 | 84 | private serializeTokenData = (tokenData: Result_5): NFTDetails => { 85 | if ('err' in tokenData) throw new Error(Object.keys(tokenData.err)[0]); 86 | const metadata = tokenData.ok.metadata as { Class: Array }; 87 | const tokenID = metadata.Class.find(({ name }) => name === 'id').value.Text; 88 | return { 89 | index: tokenID, 90 | canister: this.canisterId, 91 | url: `https://${this.canisterId}.raw.icp0.io/-/${tokenID}`, // add "/info" for metadata route 92 | name: tokenID, 93 | metadata: metadata, 94 | standard: this.standard, 95 | }; 96 | }; 97 | } 98 | -------------------------------------------------------------------------------- /src/standard_wrappers/token_standards/dip20Methods.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/camelcase */ 2 | import { Principal } from '@dfinity/principal'; 3 | import { ActorSubclass } from '@dfinity/agent'; 4 | 5 | import Dip20Service from '../../interfaces/dip_20'; 6 | import { Metadata } from '../../interfaces/token'; 7 | import { 8 | ApproveParams, 9 | BalanceResponse, 10 | BurnParams, 11 | getDecimalsFromMetadata, 12 | InternalTokenMethods, 13 | SendParams, 14 | SendResponse, 15 | } from './methods'; 16 | import { BaseMethodsExtendedActor } from '../../utils/actorFactory'; 17 | 18 | type BaseDip20Service = BaseMethodsExtendedActor; 19 | 20 | const getMetadata = async ( 21 | actor: ActorSubclass 22 | ): Promise => { 23 | const metadataResult = await actor._getMetadata(); 24 | return { 25 | fungible: { 26 | symbol: metadataResult.symbol, 27 | decimals: metadataResult.decimals, 28 | name: metadataResult.name, 29 | logo: metadataResult.logo, 30 | fee: metadataResult.fee, 31 | totalSupply: metadataResult.totalSupply, 32 | owner: metadataResult.owner, 33 | }, 34 | }; 35 | }; 36 | 37 | const send = async ( 38 | actor: ActorSubclass, 39 | { to, amount }: SendParams 40 | ): Promise => { 41 | const transferResult = await actor._transfer(Principal.fromText(to), amount); 42 | 43 | if ('Ok' in transferResult) 44 | return { transactionId: transferResult.Ok.toString() }; 45 | 46 | throw new Error(Object.keys(transferResult.Err)[0]); 47 | }; 48 | 49 | const getBalance = async ( 50 | actor: ActorSubclass, 51 | user: Principal 52 | ): Promise => { 53 | const decimals = await getDecimals(actor); 54 | const value = (await actor._balanceOf(user)).toString(); 55 | return { value, decimals }; 56 | }; 57 | 58 | const burnXTC = async ( 59 | _actor: ActorSubclass, 60 | _params: BurnParams 61 | ) => { 62 | throw new Error('BURN NOT SUPPORTED'); 63 | }; 64 | 65 | const approve = async ( 66 | actor: ActorSubclass, 67 | params: ApproveParams 68 | ) => { 69 | return actor._approve(params.spender, params.amount); 70 | }; 71 | 72 | const getDecimals = async (actor: ActorSubclass) => 73 | getDecimalsFromMetadata(await getMetadata(actor)); 74 | 75 | export default { 76 | send, 77 | getMetadata, 78 | getBalance, 79 | burnXTC, 80 | getDecimals, 81 | approve, 82 | } as InternalTokenMethods; 83 | -------------------------------------------------------------------------------- /src/standard_wrappers/token_standards/drc20Methods.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/camelcase */ 2 | import { Principal } from '@dfinity/principal'; 3 | import { ActorSubclass } from '@dfinity/agent'; 4 | 5 | import Drc20Service from '../../interfaces/drc_20'; 6 | import { Metadata } from '../../interfaces/token'; 7 | import { 8 | ApproveParams, 9 | BalanceResponse, 10 | BurnParams, 11 | getDecimalsFromMetadata, 12 | InternalTokenMethods, 13 | SendParams, 14 | SendResponse, 15 | } from './methods'; 16 | import { BaseMethodsExtendedActor } from '../../utils/actorFactory'; 17 | 18 | type BaseDrc20Service = BaseMethodsExtendedActor; 19 | 20 | const getMetadata = async ( 21 | actor: ActorSubclass 22 | ): Promise => { 23 | const metadata = await actor._drc20_metadata(); 24 | const symbol = await actor._drc20_symbol(); 25 | const decimals = await actor._drc20_decimals(); 26 | const name = await actor._drc20_name(); 27 | const fee = await actor._drc20_fee(); 28 | const totalSupply = await actor._drc20_totalSupply(); 29 | 30 | return { 31 | fungible: { 32 | symbol, 33 | decimals, 34 | name, 35 | logo: metadata.find((item) => item?.name === 'logo')?.[0]?.content, 36 | fee, 37 | totalSupply, 38 | }, 39 | }; 40 | }; 41 | 42 | const send = async ( 43 | actor: ActorSubclass, 44 | { to, amount }: SendParams 45 | ): Promise => { 46 | const transferResult = await actor._drc20_transfer(to, amount, [], [], []); 47 | 48 | if ('ok' in transferResult) 49 | return { transactionId: transferResult.ok.toString() }; 50 | 51 | throw new Error(transferResult.err.message); 52 | }; 53 | 54 | const getBalance = async ( 55 | actor: ActorSubclass, 56 | user: Principal 57 | ): Promise => { 58 | const decimals = await getDecimals(actor); 59 | const value = (await actor._drc20_balanceOf(user.toString())).toString(); 60 | return { value, decimals }; 61 | }; 62 | 63 | const burnXTC = async ( 64 | _actor: ActorSubclass, 65 | _params: BurnParams 66 | ) => { 67 | throw new Error('BURN NOT SUPPORTED'); 68 | }; 69 | 70 | const approve = async ( 71 | actor: ActorSubclass, 72 | params: ApproveParams 73 | ) => { 74 | return actor._drc20_approve( 75 | params.spender.toString(), 76 | params.amount, 77 | [], 78 | [], 79 | [] 80 | ); 81 | }; 82 | 83 | const getDecimals = async (actor: ActorSubclass) => 84 | getDecimalsFromMetadata(await getMetadata(actor)); 85 | 86 | export default { 87 | send, 88 | getMetadata, 89 | getBalance, 90 | burnXTC, 91 | getDecimals, 92 | approve, 93 | } as InternalTokenMethods; 94 | -------------------------------------------------------------------------------- /src/standard_wrappers/token_standards/extMethods.ts: -------------------------------------------------------------------------------- 1 | import { ActorSubclass, Actor } from '@dfinity/agent'; 2 | import { Principal } from '@dfinity/principal'; 3 | 4 | import ExtService from '../../interfaces/ext'; 5 | import { Metadata } from '../../interfaces/token'; 6 | import { BaseMethodsExtendedActor } from '../../utils/actorFactory'; 7 | import { 8 | ApproveParams, 9 | BalanceResponse, 10 | BurnParams, 11 | getDecimalsFromMetadata, 12 | InternalTokenMethods, 13 | SendParams, 14 | SendResponse, 15 | } from './methods'; 16 | 17 | type BaseExtService = BaseMethodsExtendedActor; 18 | 19 | const getMetadata = async ( 20 | actor: ActorSubclass 21 | ): Promise => { 22 | actor._balance; 23 | const token = Actor.canisterIdOf(actor).toText(); 24 | 25 | const extensions = await actor._extensions(); 26 | if (!extensions.includes('@ext/common')) 27 | throw new Error( 28 | 'The provided canister does not implement commont extension' 29 | ); 30 | const metadataResult = await actor._metadata(token); 31 | 32 | if ('ok' in metadataResult) return metadataResult.ok; 33 | 34 | throw new Error(Object.keys(metadataResult.err)[0]); 35 | }; 36 | 37 | const send = async ( 38 | actor: ActorSubclass, 39 | { to, from, amount }: SendParams 40 | ): Promise => { 41 | const dummyMemmo = new Array(32).fill(0); 42 | const token = Actor.canisterIdOf(actor).toText(); 43 | const data = { 44 | to: { principal: Principal.fromText(to) }, 45 | from: { principal: Principal.from(from) }, 46 | amount, 47 | token, 48 | memo: dummyMemmo, 49 | notify: false, 50 | subaccount: [], 51 | fee: BigInt(0), 52 | }; 53 | 54 | const transferResult = await actor._transfer(data); 55 | 56 | if ('ok' in transferResult) return { amount: transferResult.ok.toString() }; 57 | 58 | throw new Error(Object.keys(transferResult.err)[0]); 59 | }; 60 | 61 | const getBalance = async ( 62 | actor: ActorSubclass, 63 | user: Principal 64 | ): Promise => { 65 | const token = Actor.canisterIdOf(actor).toText(); 66 | 67 | const balanceResult = await actor._balance({ 68 | token, 69 | user: { principal: user }, 70 | }); 71 | 72 | const decimals = await getDecimals(actor); 73 | 74 | if ('ok' in balanceResult) 75 | return { value: balanceResult.ok.toString(), decimals }; 76 | 77 | throw new Error(Object.keys(balanceResult.err)[0]); 78 | }; 79 | 80 | const burnXTC = async ( 81 | _actor: ActorSubclass, 82 | _params: BurnParams 83 | ) => { 84 | throw new Error('BURN NOT SUPPORTED'); 85 | }; 86 | 87 | const approve = async ( 88 | _actor: ActorSubclass, 89 | _params: ApproveParams 90 | ) => { 91 | throw new Error('APPROVE NOT SUPPORTED'); 92 | }; 93 | 94 | const getDecimals = async (actor: ActorSubclass) => 95 | getDecimalsFromMetadata(await getMetadata(actor)); 96 | 97 | export default { 98 | send, 99 | getMetadata, 100 | getBalance, 101 | burnXTC, 102 | getDecimals, 103 | approve, 104 | } as InternalTokenMethods; 105 | -------------------------------------------------------------------------------- /src/standard_wrappers/token_standards/icpStandardMethods.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/camelcase */ 2 | import { Principal } from '@dfinity/principal'; 3 | import { Actor, ActorSubclass, HttpAgent } from '@dfinity/agent'; 4 | 5 | import LedgerService from '../../interfaces/ledger'; 6 | import { FungibleMetadata, Metadata } from '../../interfaces/token'; 7 | import { 8 | ApproveParams, 9 | BalanceResponse, 10 | BurnParams, 11 | getDecimalsFromMetadata, 12 | InternalTokenMethods, 13 | SendParams, 14 | SendResponse, 15 | } from './methods'; 16 | import { BaseMethodsExtendedActor } from '../../utils/actorFactory'; 17 | import { getAccountId } from '../../utils/account'; 18 | import { validatePrincipalId } from '../../utils/validations'; 19 | import { TokenRegistry } from '../../registries'; 20 | 21 | type BaseLedgerService = BaseMethodsExtendedActor; 22 | 23 | const getMetadata = async ( 24 | _actor: ActorSubclass 25 | ): Promise => { 26 | const agent = Actor.agentOf(_actor) as HttpAgent; 27 | try { 28 | const tokenRegistry = new TokenRegistry(agent); 29 | const token = await tokenRegistry.get( 30 | Actor.canisterIdOf(_actor).toString() 31 | ); 32 | const { fee = 0.002, decimals = 8 } = token?.details || {}; 33 | const numberFee = Number(fee?.toString?.()); 34 | const numberDecimals = Number(decimals?.toString?.()); 35 | const parsedFee = numberFee * 10 ** numberDecimals; 36 | return { 37 | fungible: { 38 | symbol: (token?.details?.symbol as string) || 'ICP', 39 | name: (token?.name as string) || 'ICP', 40 | decimals: numberDecimals, 41 | fee: parsedFee, 42 | }, 43 | }; 44 | } catch (e) { 45 | console.error( 46 | 'Error while fetching token metadata, falling back to default values', 47 | e 48 | ); 49 | // Fallback to default ICP values when dab is unavailable 50 | return { 51 | fungible: { 52 | symbol: 'ICP', 53 | name: 'ICP', 54 | decimals: 8, 55 | fee: 10000, 56 | }, 57 | }; 58 | } 59 | }; 60 | 61 | const send = async ( 62 | actor: ActorSubclass, 63 | { to, amount, opts }: SendParams 64 | ): Promise => { 65 | const metadata = await getMetadata(actor); 66 | const { fee = 0.002, decimals = BigInt(8) } = 67 | (metadata as FungibleMetadata)?.fungible || {}; 68 | const defaultArgs = { 69 | fee: BigInt((fee as number) * 10 ** parseInt(decimals.toString(), 10)), 70 | memo: BigInt(0), 71 | }; 72 | const response = await actor._send_dfx({ 73 | to: validatePrincipalId(to) ? getAccountId(Principal.fromText(to)) : to, 74 | fee: { e8s: opts?.fee || defaultArgs.fee }, 75 | amount: { e8s: amount }, 76 | memo: opts?.memo ? BigInt(opts.memo) : defaultArgs.memo, 77 | from_subaccount: [], // For now, using default subaccount to handle ICP 78 | created_at_time: [], 79 | }); 80 | 81 | return { height: await response.toString() }; 82 | }; 83 | 84 | const getBalance = async ( 85 | actor: ActorSubclass, 86 | user: Principal 87 | ): Promise => { 88 | try { 89 | const account = getAccountId(user); 90 | const balance = await actor._account_balance_dfx({ account }); 91 | return { value: balance.e8s.toString(), decimals: 8 }; 92 | } catch (e) { 93 | return { 94 | value: 'Error', 95 | decimals: 8, 96 | error: 'Error while fetching your balance', 97 | }; 98 | } 99 | }; 100 | 101 | const burnXTC = async ( 102 | _actor: ActorSubclass, 103 | _params: BurnParams 104 | ) => { 105 | throw new Error('BURN NOT SUPPORTED'); 106 | }; 107 | 108 | const approve = async ( 109 | _actor: ActorSubclass, 110 | _params: ApproveParams 111 | ) => { 112 | throw new Error('APPROVE NOT SUPPORTED'); 113 | }; 114 | 115 | const getDecimals = async (actor: ActorSubclass) => 116 | getDecimalsFromMetadata(await getMetadata(actor)); 117 | 118 | export default { 119 | send, 120 | getMetadata, 121 | getBalance, 122 | burnXTC, 123 | getDecimals, 124 | approve, 125 | } as InternalTokenMethods; 126 | -------------------------------------------------------------------------------- /src/standard_wrappers/token_standards/icrc1Methods.ts: -------------------------------------------------------------------------------- 1 | import { 2 | InternalTokenMethods, 3 | getDecimalsFromMetadata, 4 | ApproveParams, 5 | } from './methods'; 6 | 7 | import { ActorSubclass } from '@dfinity/agent'; 8 | import { BaseMethodsExtendedActor } from '../../utils/actorFactory'; 9 | import { 10 | BalanceResponse, 11 | BurnParams, 12 | FungibleMetadata, 13 | Metadata, 14 | SendParams, 15 | SendResponse, 16 | } from '../../interfaces/token'; 17 | import ICRC1Service from '../../interfaces/icrc_1'; 18 | import { Principal } from '@dfinity/principal'; 19 | 20 | type BaseICRC1Service = BaseMethodsExtendedActor; 21 | 22 | const getMetadata = async ( 23 | actor: ActorSubclass 24 | ): Promise => { 25 | const metadataResult = await actor._icrc1_metadata(); 26 | const symbol = await actor._icrc1_symbol(); 27 | const decimals = await actor._icrc1_decimals(); 28 | const name = await actor._icrc1_name(); 29 | const fee = await actor._icrc1_fee(); 30 | const totalSupply = await actor._icrc1_total_supply(); 31 | const mintingAccount = await actor._icrc1_minting_account(); 32 | 33 | const logo = metadataResult.find(([name]) => name === 'icrc1:logo')?.[1]; 34 | const owner = !mintingAccount[0] 35 | ? Principal.anonymous() 36 | : mintingAccount[0].owner; 37 | 38 | return { 39 | fungible: { 40 | symbol, 41 | decimals, 42 | name, 43 | fee, 44 | totalSupply, 45 | logo: logo?.['Text'] || '', 46 | owner, 47 | }, 48 | }; 49 | }; 50 | 51 | const getBalance = async ( 52 | actor: ActorSubclass, 53 | user: Principal 54 | ): Promise => { 55 | try { 56 | const balance = await actor._icrc1_balance_of({ 57 | owner: user, 58 | subaccount: [], 59 | }); 60 | return { value: balance.toString(), decimals: 8 }; 61 | } catch (e) { 62 | return { 63 | value: 'Error', 64 | decimals: 8, 65 | error: `Error while fetching your balance: ${e.message}`, 66 | }; 67 | } 68 | }; 69 | 70 | const send = async ( 71 | actor: ActorSubclass, 72 | { to, amount, opts }: SendParams 73 | ): Promise => { 74 | const metadata = await getMetadata(actor); 75 | const { fee = 0.002, decimals = BigInt(8) } = 76 | (metadata as FungibleMetadata)?.fungible || {}; 77 | const defaultArgs = { 78 | fee, 79 | memo: [], 80 | subaccount: [], 81 | }; 82 | 83 | const response = await actor._icrc1_transfer({ 84 | to: { 85 | owner: Principal.fromText(to), 86 | subaccount: opts?.to_subaccount || defaultArgs.subaccount, 87 | }, 88 | fee: [opts?.fee ? BigInt(opts?.fee) : BigInt(defaultArgs.fee)], 89 | memo: [opts.memo ? [Number(opts.memo)] : defaultArgs.memo], 90 | from_subaccount: [], 91 | created_at_time: [], 92 | amount, 93 | }); 94 | 95 | if (response['Err']) { 96 | return Promise.reject(response['Err']); 97 | } 98 | 99 | return { height: response['Ok'].toString() }; 100 | }; 101 | 102 | const burnXTC = async ( 103 | _actor: ActorSubclass, 104 | _params: BurnParams 105 | ) => { 106 | throw new Error('BURN NOT SUPPORTED'); 107 | }; 108 | 109 | const approve = async ( 110 | _actor: ActorSubclass, 111 | _params: ApproveParams 112 | ) => { 113 | throw new Error('APPROVE NOT SUPPORTED'); 114 | }; 115 | 116 | const getDecimals = async (actor: ActorSubclass) => 117 | getDecimalsFromMetadata(await getMetadata(actor)); 118 | 119 | export default { 120 | getMetadata, 121 | getBalance, 122 | send, 123 | burnXTC, 124 | getDecimals, 125 | approve, 126 | } as InternalTokenMethods; 127 | -------------------------------------------------------------------------------- /src/standard_wrappers/token_standards/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | HttpAgent, 3 | ActorSubclass, 4 | blsVerify, 5 | CreateCertificateOptions, 6 | } from '@dfinity/agent'; 7 | import { Principal } from '@dfinity/principal'; 8 | import { IDL } from '@dfinity/candid'; 9 | 10 | import { createExtendedActorClass } from '../../utils/actorFactory'; 11 | import defaultMethods, { 12 | BalanceResponse, 13 | InternalTokenMethods, 14 | TokenServiceExtended, 15 | } from './methods'; 16 | import xtcMethods from './xtcMethods'; 17 | import extMethods from './extMethods'; 18 | import dip20Methods from './dip20Methods'; 19 | import extIDL from '../../idls/ext.did'; 20 | import xtcIDL from '../../idls/xtc.did'; 21 | import icrc1IDL from '../../idls/icrc_1.did'; 22 | import dip20IDL from '../../idls/dip_20.did'; 23 | import drc20IDL from '../../idls/drc_20.did'; 24 | import icpIDL from '../../idls/ledger.did'; 25 | import { TOKEN } from '../../constants/standards'; 26 | import wicpIDL from '../../idls/wicp.did'; 27 | import wicpMethods from './wicpMethods'; 28 | import rosettaMethods from './rosettaMethods'; 29 | import icpStandardMethods from './icpStandardMethods'; 30 | import icrc1Methods from './icrc1Methods'; 31 | import drc20Methods from './drc20Methods'; 32 | 33 | const getMethods = (standard: string): InternalTokenMethods => 34 | ({ 35 | [TOKEN.xtc]: xtcMethods, 36 | [TOKEN.ext]: extMethods, 37 | [TOKEN.dip20]: dip20Methods, 38 | [TOKEN.wicp]: wicpMethods, 39 | [TOKEN.rosetta]: rosettaMethods, 40 | [TOKEN.icp]: icpStandardMethods, 41 | [TOKEN.icrc1]: icrc1Methods, 42 | [TOKEN.drc20]: drc20Methods, 43 | }[standard] || defaultMethods); 44 | 45 | const getIdl = (standard: string): IDL.InterfaceFactory => { 46 | const idl = { 47 | [TOKEN.xtc]: xtcIDL, 48 | [TOKEN.ext]: extIDL, 49 | [TOKEN.dip20]: dip20IDL, 50 | [TOKEN.wicp]: wicpIDL, 51 | [TOKEN.rosetta]: icpIDL, 52 | [TOKEN.icp]: icpIDL, 53 | [TOKEN.icrc1]: icrc1IDL, 54 | [TOKEN.drc20]: drc20IDL, 55 | }[standard]; 56 | if (!idl) throw new Error(`Standard ${standard} Not Implemented`); 57 | return idl; 58 | }; 59 | 60 | export const createTokenActor = async ( 61 | canisterId: string | Principal, 62 | agent: HttpAgent, 63 | standard: string, 64 | blsVerify?: CreateCertificateOptions['blsVerify'] 65 | ): Promise>> => { 66 | const idl = getIdl(standard); 67 | const actor = new (createExtendedActorClass( 68 | agent, 69 | getMethods(standard), 70 | canisterId, 71 | idl, 72 | blsVerify 73 | ))() as unknown as ActorSubclass>; 74 | return actor; 75 | }; 76 | 77 | export const parseBalance = (balance: BalanceResponse): string => { 78 | return (parseInt(balance.value, 10) / 10 ** balance.decimals).toString(); 79 | }; 80 | 81 | export default {}; 82 | 83 | export { SendResponse } from './methods'; 84 | -------------------------------------------------------------------------------- /src/standard_wrappers/token_standards/methods.ts: -------------------------------------------------------------------------------- 1 | import { ActorSubclass } from '@dfinity/agent'; 2 | import { Principal } from '@dfinity/principal'; 3 | 4 | import { Metadata } from '../../interfaces/token'; 5 | import { BurnResult } from '../../interfaces/xtc'; 6 | import { TxnResult } from '../../interfaces/drc_20'; 7 | import { Result } from '../../interfaces/dip_20'; 8 | import { BaseMethodsExtendedActor } from '../../utils/actorFactory'; 9 | 10 | interface TimeStamp { 11 | timestamp_nanos: bigint; 12 | } 13 | export interface SendOpts { 14 | fee?: bigint; 15 | memo?: string; 16 | from_subaccount?: number; 17 | to_subaccount?: Uint8Array | number[]; 18 | created_at_time?: TimeStamp; // TODO: create js Date to TimeStamp function 19 | } 20 | 21 | export type SendResponse = 22 | | { height: string } 23 | | { amount: string } 24 | | { transactionId: string }; 25 | 26 | export interface SendParams { 27 | to: string; 28 | from: string; 29 | amount: bigint; 30 | opts?: any; 31 | } 32 | 33 | export interface BurnParams { 34 | to: Principal; 35 | amount: string; 36 | } 37 | 38 | export interface ApproveParams { 39 | spender: Principal; 40 | amount: bigint; 41 | nonce?: bigint; 42 | } 43 | 44 | export interface BalanceResponse { 45 | value: string; 46 | decimals: number; 47 | error?: string; 48 | } 49 | 50 | export type ApproveResponse = Result | TxnResult; 51 | 52 | interface AddedMehtodsToken { 53 | send: ({ to, from, amount }: SendParams) => Promise; 54 | getMetadata: () => Promise; 55 | getBalance: (user: Principal) => Promise; 56 | burnXTC: ({ to, amount }: BurnParams) => Promise; 57 | getDecimals: () => Promise; 58 | approve: ({ 59 | spender, 60 | amount, 61 | nonce, 62 | }: ApproveParams) => Promise; 63 | } 64 | 65 | export type TokenServiceExtended = BaseMethodsExtendedActor & 66 | AddedMehtodsToken; 67 | 68 | export interface InternalTokenMethods { 69 | send: ( 70 | actor: ActorSubclass, 71 | { to, from, amount }: SendParams 72 | ) => Promise; 73 | getMetadata: (actor: ActorSubclass) => Promise; 74 | getBalance: ( 75 | actor: ActorSubclass, 76 | user: Principal 77 | ) => Promise; 78 | burnXTC: ( 79 | actor: ActorSubclass, 80 | { to, amount }: BurnParams 81 | ) => Promise; 82 | getDecimals: (actor: ActorSubclass) => Promise; 83 | approve: ( 84 | actor: ActorSubclass, 85 | { spender, amount, nonce }: ApproveParams 86 | ) => Promise; 87 | } 88 | 89 | const send = async ( 90 | _actor: ActorSubclass, 91 | _params: SendParams 92 | ): Promise => { 93 | throw Error('Standard Not Implemented'); 94 | }; 95 | 96 | const getMetadata = async (_actor: ActorSubclass): Promise => { 97 | throw Error('Standard Not Implemented'); 98 | }; 99 | 100 | const getBalance = async ( 101 | _actor: ActorSubclass, 102 | _user: Principal 103 | ): Promise => { 104 | throw Error('Standard Not Implemented'); 105 | }; 106 | 107 | const burnXTC = async (_actor: ActorSubclass, _params: BurnParams) => { 108 | throw Error('Standard Not Implemented'); 109 | }; 110 | 111 | const getDecimals = async (_actor: ActorSubclass) => { 112 | throw Error('Standard Not Implemented'); 113 | }; 114 | 115 | const approve = async (_actor: ActorSubclass) => { 116 | throw Error('Standard Not Implemented'); 117 | }; 118 | 119 | export const getDecimalsFromMetadata = (metadata: Metadata): number => { 120 | return 'fungible' in metadata ? metadata.fungible.decimals : 0; 121 | }; 122 | 123 | export const parseAmountToSend = (amount: string, decimals: number): bigint => { 124 | return BigInt(parseFloat(amount) * 10 ** decimals); 125 | }; 126 | 127 | export default { 128 | send, 129 | getMetadata, 130 | getBalance, 131 | burnXTC, 132 | getDecimals, 133 | approve, 134 | } as InternalTokenMethods; 135 | -------------------------------------------------------------------------------- /src/standard_wrappers/token_standards/rosettaMethods.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/camelcase */ 2 | import { Principal } from '@dfinity/principal'; 3 | import { ActorSubclass } from '@dfinity/agent'; 4 | 5 | import LedgerService from '../../interfaces/ledger'; 6 | import { Metadata } from '../../interfaces/ext'; 7 | import { 8 | ApproveParams, 9 | BalanceResponse, 10 | BurnParams, 11 | getDecimalsFromMetadata, 12 | InternalTokenMethods, 13 | SendParams, 14 | SendResponse, 15 | } from './methods'; 16 | import { BaseMethodsExtendedActor } from '../../utils/actorFactory'; 17 | import { getAccountId } from '../../utils/account'; 18 | import { isValidPrincipal } from '../../utils/validations'; 19 | 20 | type BaseLedgerService = BaseMethodsExtendedActor; 21 | 22 | const DECIMALS = 8; 23 | 24 | const NET_ID = { 25 | blockchain: 'Internet Computer', 26 | network: '00000000000000020101', 27 | }; 28 | const ROSETTA_URL = 'https://rosetta-api.internetcomputer.org'; 29 | 30 | const getMetadata = async ( 31 | _actor: ActorSubclass 32 | ): Promise => { 33 | return { 34 | fungible: { 35 | symbol: 'ICP', 36 | decimals: DECIMALS, 37 | name: 'ICP', 38 | fee: 10000, 39 | }, 40 | }; 41 | }; 42 | 43 | const send = async ( 44 | actor: ActorSubclass, 45 | { to, amount, opts }: SendParams 46 | ): Promise => { 47 | const defaultArgs = { 48 | fee: BigInt(10000), 49 | memo: BigInt(0), 50 | }; 51 | const response = await actor._send_dfx({ 52 | to: isValidPrincipal(to) ? getAccountId(Principal.fromText(to)) : to, 53 | fee: { e8s: opts?.fee || defaultArgs.fee }, 54 | amount: { e8s: amount }, 55 | memo: opts?.memo ? BigInt(opts.memo) : defaultArgs.memo, 56 | from_subaccount: [], // For now, using default subaccount to handle ICP 57 | created_at_time: [], 58 | }); 59 | 60 | return { height: await response.toString() }; 61 | }; 62 | 63 | const getBalance = async ( 64 | actor: ActorSubclass, 65 | user: Principal 66 | ): Promise => { 67 | const accountId = getAccountId(user); 68 | const decimals = await getDecimals(actor); 69 | const response = await fetch(`${ROSETTA_URL}/account/balance`, { 70 | method: 'POST', 71 | body: JSON.stringify({ 72 | network_identifier: NET_ID, 73 | account_identifier: { 74 | address: accountId, 75 | }, 76 | }), 77 | headers: { 78 | 'Content-Type': 'application/json', 79 | Accept: '*/*', 80 | }, 81 | }); 82 | if (!response.ok) { 83 | return { value: 'Error', decimals, error: response.statusText }; 84 | } 85 | 86 | // @ts-ignore 87 | const { balances } = await response.json(); 88 | const [{ value, currency }] = balances; 89 | return { value, decimals: currency.decimals }; 90 | }; 91 | 92 | const burnXTC = async ( 93 | _actor: ActorSubclass, 94 | _params: BurnParams 95 | ) => { 96 | throw new Error('BURN NOT SUPPORTED'); 97 | }; 98 | 99 | const approve = async ( 100 | _actor: ActorSubclass, 101 | _params: ApproveParams 102 | ) => { 103 | throw new Error('APPROVE NOT SUPPORTED'); 104 | }; 105 | 106 | const getDecimals = async (actor: ActorSubclass) => 107 | getDecimalsFromMetadata(await getMetadata(actor)); 108 | 109 | export default { 110 | send, 111 | getMetadata, 112 | getBalance, 113 | burnXTC, 114 | getDecimals, 115 | approve, 116 | } as InternalTokenMethods; 117 | -------------------------------------------------------------------------------- /src/standard_wrappers/token_standards/wicpMethods.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/camelcase */ 2 | import { Principal } from '@dfinity/principal'; 3 | import { ActorSubclass } from '@dfinity/agent'; 4 | 5 | import WICPService from '../../interfaces/wicp'; 6 | import { Metadata } from '../../interfaces/token'; 7 | import { 8 | ApproveParams, 9 | BalanceResponse, 10 | BurnParams, 11 | getDecimalsFromMetadata, 12 | InternalTokenMethods, 13 | SendParams, 14 | SendResponse, 15 | } from './methods'; 16 | import { BaseMethodsExtendedActor } from '../../utils/actorFactory'; 17 | 18 | type BaseWICPService = BaseMethodsExtendedActor; 19 | 20 | const getMetadata = async ( 21 | actor: ActorSubclass 22 | ): Promise => { 23 | const metadataResult = await actor._getMetadata(); 24 | return { 25 | fungible: { 26 | symbol: metadataResult.symbol, 27 | decimals: metadataResult.decimals, 28 | name: metadataResult.name, 29 | logo: metadataResult.logo, 30 | fee: metadataResult.fee, 31 | totalSupply: metadataResult.totalSupply, 32 | owner: metadataResult.owner, 33 | }, 34 | }; 35 | }; 36 | 37 | const send = async ( 38 | actor: ActorSubclass, 39 | { to, amount }: SendParams 40 | ): Promise => { 41 | const transferResult = await actor._transfer(Principal.fromText(to), amount); 42 | 43 | if ('Ok' in transferResult) 44 | return { transactionId: transferResult.Ok.toString() }; 45 | 46 | throw new Error(Object.keys(transferResult.Err)[0]); 47 | }; 48 | 49 | const getBalance = async ( 50 | actor: ActorSubclass, 51 | user: Principal 52 | ): Promise => { 53 | const decimals = await getDecimals(actor); 54 | const value = (await actor._balanceOf(user)).toString(); 55 | return { value, decimals }; 56 | }; 57 | 58 | const burnXTC = async ( 59 | _actor: ActorSubclass, 60 | _params: BurnParams 61 | ) => { 62 | throw new Error('BURN NOT SUPPORTED'); 63 | }; 64 | 65 | const approve = async ( 66 | _actor: ActorSubclass, 67 | _params: ApproveParams 68 | ) => { 69 | throw new Error('APPROVE NOT SUPPORTED'); 70 | }; 71 | 72 | const getDecimals = async (actor: ActorSubclass) => 73 | getDecimalsFromMetadata(await getMetadata(actor)); 74 | 75 | export default { 76 | send, 77 | getMetadata, 78 | getBalance, 79 | burnXTC, 80 | getDecimals, 81 | approve, 82 | } as InternalTokenMethods; 83 | -------------------------------------------------------------------------------- /src/standard_wrappers/token_standards/xtcMethods.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/camelcase */ 2 | import { Principal } from '@dfinity/principal'; 3 | import { ActorSubclass } from '@dfinity/agent'; 4 | 5 | import XtcService, { BurnResult } from '../../interfaces/xtc'; 6 | import { Metadata } from '../../interfaces/token'; 7 | import { 8 | BalanceResponse, 9 | BurnParams, 10 | getDecimalsFromMetadata, 11 | InternalTokenMethods, 12 | parseAmountToSend, 13 | SendParams, 14 | SendResponse, 15 | } from './methods'; 16 | import { BaseMethodsExtendedActor } from '../../utils/actorFactory'; 17 | 18 | type BaseXtcService = BaseMethodsExtendedActor; 19 | 20 | const getMetadata = async ( 21 | actor: ActorSubclass 22 | ): Promise => { 23 | const metadataResult = await actor._getMetadata(); 24 | return { 25 | fungible: { 26 | symbol: metadataResult.symbol, 27 | decimals: metadataResult.decimals, 28 | name: metadataResult.name, 29 | logo: metadataResult.logo, 30 | fee: metadataResult.fee, 31 | totalSupply: metadataResult.totalSupply, 32 | owner: metadataResult.owner, 33 | }, 34 | }; 35 | }; 36 | 37 | const send = async ( 38 | actor: ActorSubclass, 39 | { to, amount }: SendParams 40 | ): Promise => { 41 | const transferResult = await actor._transferErc20( 42 | Principal.fromText(to), 43 | amount 44 | ); 45 | 46 | if ('Ok' in transferResult) 47 | return { transactionId: transferResult.Ok.toString() }; 48 | 49 | throw new Error(Object.keys(transferResult.Err)[0]); 50 | }; 51 | 52 | const getBalance = async ( 53 | actor: ActorSubclass, 54 | user: Principal 55 | ): Promise => { 56 | const decimals = await getDecimals(actor); 57 | const value = (await actor._balanceOf(user)).toString(); 58 | return { value, decimals }; 59 | }; 60 | 61 | const burnXTC = async ( 62 | actor: ActorSubclass, 63 | { to, amount }: BurnParams 64 | ): Promise => { 65 | const decimals = await getDecimals(actor); 66 | const parsedAmount = parseAmountToSend(amount, decimals); 67 | return actor._burn({ canister_id: to, amount: parsedAmount }); 68 | }; 69 | 70 | const getDecimals = async (actor: ActorSubclass) => 71 | getDecimalsFromMetadata(await getMetadata(actor)); 72 | 73 | export default { 74 | send, 75 | getMetadata, 76 | getBalance, 77 | burnXTC, 78 | getDecimals, 79 | } as InternalTokenMethods; 80 | -------------------------------------------------------------------------------- /src/utils/account.ts: -------------------------------------------------------------------------------- 1 | import { Principal } from '@dfinity/principal'; 2 | import CryptoJS from 'crypto-js'; 3 | import crc32 from 'buffer-crc32'; 4 | 5 | const ACCOUNT_DOMAIN_SEPERATOR = '\x0Aaccount-id'; 6 | const SUB_ACCOUNT_ZERO = Buffer.alloc(32); 7 | 8 | const byteArrayToWordArray = (byteArray: Uint8Array) => { 9 | const wordArray = [] as any; 10 | let i; 11 | for (i = 0; i < byteArray.length; i += 1) { 12 | wordArray[(i / 4) | 0] |= byteArray[i] << (24 - 8 * i); 13 | } 14 | // eslint-disable-next-line 15 | const result = CryptoJS.lib.WordArray.create(wordArray, byteArray.length); 16 | return result; 17 | }; 18 | 19 | const wordToByteArray = (word, length): number[] => { 20 | const byteArray: number[] = []; 21 | const xFF = 0xff; 22 | if (length > 0) byteArray.push(word >>> 24); 23 | if (length > 1) byteArray.push((word >>> 16) & xFF); 24 | if (length > 2) byteArray.push((word >>> 8) & xFF); 25 | if (length > 3) byteArray.push(word & xFF); 26 | 27 | return byteArray; 28 | }; 29 | 30 | const wordArrayToByteArray = (wordArray, length) => { 31 | if ( 32 | wordArray.hasOwnProperty('sigBytes') && 33 | wordArray.hasOwnProperty('words') 34 | ) { 35 | length = wordArray.sigBytes; 36 | wordArray = wordArray.words; 37 | } 38 | 39 | let result: number[] = []; 40 | let bytes; 41 | let i = 0; 42 | while (length > 0) { 43 | bytes = wordToByteArray(wordArray[i], Math.min(4, length)); 44 | length -= bytes.length; 45 | result = [...result, bytes]; 46 | i++; 47 | } 48 | return [].concat.apply([], result); 49 | }; 50 | 51 | const intToHex = (val: number) => 52 | val < 0 ? (Number(val) >>> 0).toString(16) : Number(val).toString(16); 53 | 54 | // We generate a CRC32 checksum, and trnasform it into a hexString 55 | const generateChecksum = (hash: Uint8Array) => { 56 | const crc = crc32.unsigned(Buffer.from(hash)); 57 | const hex = intToHex(crc); 58 | return hex.padStart(8, '0'); 59 | }; 60 | 61 | /* 62 | Used dfinity/keysmith/account/account.go as a base for the ID generation 63 | */ 64 | export const getAccountId = ( 65 | principal: Principal, 66 | subAccount?: number 67 | ): string => { 68 | const sha = CryptoJS.algo.SHA224.create(); 69 | sha.update(ACCOUNT_DOMAIN_SEPERATOR); // Internally parsed with UTF-8, like go does 70 | sha.update(byteArrayToWordArray(principal.toUint8Array())); 71 | const subBuffer = Buffer.from(SUB_ACCOUNT_ZERO); 72 | if (subAccount) { 73 | subBuffer.writeUInt32BE(subAccount); 74 | } 75 | sha.update(byteArrayToWordArray(subBuffer)); 76 | const hash = sha.finalize(); 77 | 78 | /// While this is backed by an array of length 28, it's canonical representation 79 | /// is a hex string of length 64. The first 8 characters are the CRC-32 encoded 80 | /// hash of the following 56 characters of hex. Both, upper and lower case 81 | /// characters are valid in the input string and can even be mixed. 82 | /// [ic/rs/rosetta-api/ledger_canister/src/account_identifier.rs] 83 | const byteArray = wordArrayToByteArray(hash, 28); 84 | const checksum = generateChecksum(byteArray); 85 | const val = checksum + hash.toString(); 86 | 87 | return val; 88 | }; 89 | 90 | export default {}; 91 | -------------------------------------------------------------------------------- /src/utils/actorFactory.ts: -------------------------------------------------------------------------------- 1 | import { 2 | HttpAgent, 3 | Actor, 4 | ActorMethod, 5 | ActorSubclass, 6 | CreateCertificateOptions, 7 | } from '@dfinity/agent'; 8 | import { IDL } from '@dfinity/candid'; 9 | import { Principal } from '@dfinity/principal'; 10 | 11 | type ExtendedActorConstructor = new () => ActorSubclass; 12 | 13 | export type BaseMethodsExtendedActor = { 14 | [K in keyof T as `_${Uncapitalize}`]: T[K]; 15 | }; 16 | 17 | export const createExtendedActorClass = ( 18 | agent: HttpAgent, 19 | methods, 20 | canisterId: string | Principal, 21 | IDLFactory: IDL.InterfaceFactory, 22 | blsVerify?: CreateCertificateOptions['blsVerify'] 23 | ): ExtendedActorConstructor => { 24 | class ExtendedActor extends Actor.createActorClass(IDLFactory) { 25 | constructor() { 26 | const principalCanisterId = 27 | typeof canisterId === 'string' 28 | ? Principal.fromText(canisterId) 29 | : canisterId; 30 | super({ agent, canisterId: principalCanisterId, blsVerify }); 31 | 32 | Object.keys(this).forEach((methodName) => { 33 | this[`_${methodName}`] = this[methodName]; 34 | }); 35 | 36 | Object.keys(methods).forEach((methodName) => { 37 | this[methodName] = ((...args: unknown[]) => 38 | methods[methodName](this, ...args) as unknown) as ActorMethod; 39 | }); 40 | } 41 | } 42 | 43 | return ExtendedActor; 44 | }; 45 | 46 | export function generateActor({ 47 | agent, 48 | canisterId, 49 | IDL, 50 | }: { 51 | agent: HttpAgent; 52 | canisterId: string; 53 | IDL: IDL.InterfaceFactory; 54 | }): ActorSubclass { 55 | return Actor.createActor(IDL, { 56 | agent, 57 | canisterId: Principal.fromText(canisterId), 58 | }); 59 | } 60 | 61 | export default { createExtendedActorClass, generateActor }; 62 | -------------------------------------------------------------------------------- /src/utils/number.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable prefer-template */ 2 | /* eslint-disable no-bitwise */ 3 | export const to32bits = (num: number): any => { 4 | const b = new ArrayBuffer(4); 5 | new DataView(b).setUint32(0, num); 6 | return Array.from(new Uint8Array(b)); 7 | }; 8 | 9 | export const from32bits = (ba: any): any => { 10 | let value; 11 | for (let i = 0; i < 4; i += 1) { 12 | value = (value << 8) | ba[i]; 13 | } 14 | return value; 15 | }; 16 | -------------------------------------------------------------------------------- /src/utils/registry.ts: -------------------------------------------------------------------------------- 1 | import { DetailType, DetailValue, Metadata } from "../interfaces/dab_registries/registry_standard"; 2 | 3 | const BOOLEAN_DETAIL_TYPE = ["True", "False"]; 4 | 5 | export type FormattedMetadata = Omit & { details: Details }; 6 | 7 | export interface Details { 8 | [key: string]: DetailType; 9 | } 10 | 11 | export const parseDetailValue = (detailValue: DetailValue): DetailType => { 12 | const key = Object.keys(detailValue)[0]; 13 | const value: DetailType = BOOLEAN_DETAIL_TYPE.includes(key) ? Boolean(key) : Object.values(detailValue)[0]; 14 | if (Array.isArray(value)) { 15 | return value.map((v) => typeof value === 'number' ? v : parseDetailValue(v)); 16 | } 17 | return value; 18 | }; 19 | 20 | export const formatRegistryDetails = (details: Metadata['details']): Details => { 21 | const formattedDetails: Details = {}; 22 | for (const [key, detailValue] of details) { 23 | formattedDetails[key] = parseDetailValue(detailValue); 24 | } 25 | return formattedDetails; 26 | }; 27 | 28 | export const formatMetadata = (metadata: Metadata): FormattedMetadata => ({ 29 | ...metadata, 30 | details: formatRegistryDetails(metadata.details), 31 | }); -------------------------------------------------------------------------------- /src/utils/validations.ts: -------------------------------------------------------------------------------- 1 | import { Principal } from '@dfinity/principal'; 2 | 3 | export const CANISTER_MAX_LENGTH = 27; 4 | export const PRINCIPAL_REGEX = /(\w{5}-){10}\w{3}/; 5 | export const ALPHANUM_REGEX = /^[a-zA-Z0-9]+$/; 6 | 7 | export const isValidPrincipal = (text: string): boolean => { 8 | try { 9 | return Principal.fromText(text).toText() === text; 10 | } catch (e) { 11 | return false; 12 | } 13 | } 14 | 15 | export const validatePrincipalId = (text: string): boolean => { 16 | try { 17 | return Boolean(PRINCIPAL_REGEX.test(text) && isValidPrincipal(text)); 18 | } catch (e) { 19 | return false; 20 | } 21 | }; 22 | export const validateAccountId = (text): boolean => 23 | text.length === 64 && ALPHANUM_REGEX.test(text); 24 | export const validateCanisterId = (text: string): boolean => { 25 | try { 26 | return Boolean( 27 | text.length <= CANISTER_MAX_LENGTH && isValidPrincipal(text) 28 | ); 29 | } catch (e) { 30 | return false; 31 | } 32 | }; 33 | 34 | export const validateToken = (metadata: any): boolean => 35 | Boolean(!!metadata.decimal && !!metadata.name && !!metadata.symbol); 36 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./dist", 4 | "rootDir": "./src", 5 | "declaration": true, 6 | "noImplicitAny": false, 7 | "esModuleInterop": true, 8 | "strictNullChecks": true, 9 | "module": "commonjs", 10 | "target": "es6", 11 | "lib": [ 12 | "es6" 13 | ], 14 | "resolveJsonModule": true, 15 | "experimentalDecorators": true, 16 | "emitDecoratorMetadata": true, 17 | "noUnusedParameters": true, 18 | "noFallthroughCasesInSwitch": true, 19 | "noImplicitReturns": true, 20 | "skipLibCheck": true, 21 | "types": ["node", "jest"] 22 | }, 23 | "compileOnSave": true, 24 | "exclude": [ 25 | "node_modules", 26 | "dist", 27 | "tests", 28 | "jest.config.cjs", 29 | ".vscode" 30 | ] 31 | } 32 | --------------------------------------------------------------------------------