@dfinity/sns 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +5 -0
  3. package/dist/candid/ledger.certified.idl.d.ts +2 -0
  4. package/dist/candid/ledger.certified.idl.js +97 -0
  5. package/dist/candid/ledger.d.ts +106 -0
  6. package/dist/candid/ledger.did +250 -0
  7. package/dist/candid/ledger.idl.d.ts +2 -0
  8. package/dist/candid/ledger.idl.js +109 -0
  9. package/dist/candid/sns_governance.certified.idl.d.ts +2 -0
  10. package/dist/candid/sns_governance.certified.idl.js +596 -0
  11. package/dist/candid/sns_governance.d.ts +366 -0
  12. package/dist/candid/sns_governance.did +303 -0
  13. package/dist/candid/sns_governance.idl.d.ts +2 -0
  14. package/dist/candid/sns_governance.idl.js +600 -0
  15. package/dist/candid/sns_root.certified.idl.d.ts +2 -0
  16. package/dist/candid/sns_root.certified.idl.js +34 -0
  17. package/dist/candid/sns_root.d.ts +28 -0
  18. package/dist/candid/sns_root.did +26 -0
  19. package/dist/candid/sns_root.idl.d.ts +2 -0
  20. package/dist/candid/sns_root.idl.js +34 -0
  21. package/dist/candid/sns_swap.certified.idl.d.ts +2 -0
  22. package/dist/candid/sns_swap.certified.idl.js +110 -0
  23. package/dist/candid/sns_swap.d.ts +81 -0
  24. package/dist/candid/sns_swap.did +61 -0
  25. package/dist/candid/sns_swap.idl.d.ts +2 -0
  26. package/dist/candid/sns_swap.idl.js +110 -0
  27. package/dist/cjs/index.cjs.js +853 -0
  28. package/dist/cjs/index.cjs.js.map +7 -0
  29. package/dist/esm/chunk-7F6PCBCJ.js +2 -0
  30. package/dist/esm/chunk-7F6PCBCJ.js.map +7 -0
  31. package/dist/esm/chunk-A576P2ZR.js +2 -0
  32. package/dist/esm/chunk-A576P2ZR.js.map +7 -0
  33. package/dist/esm/chunk-LXL5LYD3.js +2 -0
  34. package/dist/esm/chunk-LXL5LYD3.js.map +7 -0
  35. package/dist/esm/chunk-RB6XGLR7.js +2 -0
  36. package/dist/esm/chunk-RB6XGLR7.js.map +7 -0
  37. package/dist/esm/chunk-VMVMYL6O.js +840 -0
  38. package/dist/esm/chunk-VMVMYL6O.js.map +7 -0
  39. package/dist/esm/chunk-WPRZTZWQ.js +2 -0
  40. package/dist/esm/chunk-WPRZTZWQ.js.map +7 -0
  41. package/dist/esm/chunk-YKP66JDM.js +2 -0
  42. package/dist/esm/chunk-YKP66JDM.js.map +7 -0
  43. package/dist/esm/chunk-YL4WAPXH.js +2 -0
  44. package/dist/esm/chunk-YL4WAPXH.js.map +7 -0
  45. package/dist/esm/governance.canister.js +2 -0
  46. package/dist/esm/governance.canister.js.map +7 -0
  47. package/dist/esm/index.js +2 -0
  48. package/dist/esm/index.js.map +7 -0
  49. package/dist/esm/ledger.canister.js +2 -0
  50. package/dist/esm/ledger.canister.js.map +7 -0
  51. package/dist/esm/root.canister.js +2 -0
  52. package/dist/esm/root.canister.js.map +7 -0
  53. package/dist/esm/sns.js +2 -0
  54. package/dist/esm/sns.js.map +7 -0
  55. package/dist/esm/sns.wrapper.js +2 -0
  56. package/dist/esm/sns.wrapper.js.map +7 -0
  57. package/dist/index.cjs.js +1 -0
  58. package/dist/index.js +1 -0
  59. package/dist/types/constants/governance.constants.d.ts +6 -0
  60. package/dist/types/governance.canister.d.ts +13 -0
  61. package/dist/types/index.d.ts +10 -0
  62. package/dist/types/ledger.canister.d.ts +6 -0
  63. package/dist/types/root.canister.d.ts +22 -0
  64. package/dist/types/services/canister.d.ts +10 -0
  65. package/dist/types/sns.d.ts +21 -0
  66. package/dist/types/sns.wrapper.d.ts +43 -0
  67. package/dist/types/types/canister.options.d.ts +8 -0
  68. package/dist/types/types/governance.params.d.ts +14 -0
  69. package/dist/types/types/query.params.d.ts +7 -0
  70. package/dist/types/utils/actor.utils.d.ts +14 -0
  71. package/dist/types/utils/agent.utils.d.ts +5 -0
  72. package/dist/types/utils/asserts.utils.d.ts +3 -0
  73. package/dist/types/utils/did.utils.d.ts +1 -0
  74. package/package.json +40 -0
@@ -0,0 +1,2 @@
1
+ import{a as i,b as s}from"./chunk-YKP66JDM.js";import{a as r,b as t}from"./chunk-VMVMYL6O.js";var e=class extends r{static create(o){let{service:n,certifiedService:a,canisterId:c}=t({options:o,idlFactory:s,certifiedIdlFactory:i});return new e(c,n,a)}};export{e as a};
2
+ //# sourceMappingURL=chunk-7F6PCBCJ.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/ledger.canister.ts"],
4
+ "sourcesContent": ["import type { _SERVICE as SnsLedgerCanister } from \"../candid/ledger\";\nimport { idlFactory as certifiedIdlFactory } from \"../candid/sns_root.certified.idl\";\nimport { idlFactory } from \"../candid/sns_root.idl\";\nimport { Canister } from \"./services/canister\";\nimport type { CanisterOptions } from \"./types/canister.options\";\nimport { createServices } from \"./utils/actor.utils\";\n\nexport class LedgerCanister extends Canister<SnsLedgerCanister> {\n static create(options: CanisterOptions<SnsLedgerCanister>) {\n const { service, certifiedService, canisterId } =\n createServices<SnsLedgerCanister>({\n options,\n idlFactory,\n certifiedIdlFactory,\n });\n\n return new LedgerCanister(canisterId, service, certifiedService);\n }\n}\n"],
5
+ "mappings": "8FAOO,GAAM,GAAN,aAA6B,EAA4B,CAC9D,MAAO,QAAO,EAA6C,CACzD,GAAM,CAAE,UAAS,mBAAkB,cACjC,EAAkC,CAChC,UACA,aACA,qBACF,CAAC,EAEH,MAAO,IAAI,GAAe,EAAY,EAAS,CAAgB,CACjE,CACF",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ var g=Object.create;var e=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var m=(b,a)=>()=>(a||b((a={exports:{}}).exports,a),a.exports),n=(b,a)=>{for(var c in a)e(b,c,{get:a[c],enumerable:!0})},l=(b,a,c,f)=>{if(a&&typeof a=="object"||typeof a=="function")for(let d of i(a))!k.call(b,d)&&d!==c&&e(b,d,{get:()=>a[d],enumerable:!(f=h(a,d))||f.enumerable});return b};var o=(b,a,c)=>(c=b!=null?g(j(b)):{},l(a||!b||!b.__esModule?e(c,"default",{value:b,enumerable:!0}):c,b));export{m as a,n as b,o as c};
2
+ //# sourceMappingURL=chunk-A576P2ZR.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import{a,b as n}from"./chunk-YKP66JDM.js";import{a as e,b as s}from"./chunk-VMVMYL6O.js";var t=class extends e{static create(r){let{service:i,certifiedService:o,canisterId:c}=s({options:r,idlFactory:n,certifiedIdlFactory:a});return new t(c,i,o)}canistersSummary=async({certified:r=!0,additionalCanisterIds:i})=>this.caller({certified:r}).get_sns_canisters_summary(i??[])};export{t as a};
2
+ //# sourceMappingURL=chunk-LXL5LYD3.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/root.canister.ts"],
4
+ "sourcesContent": ["import type { Principal } from \"@dfinity/principal\";\nimport type {\n CanisterStatusResultV2,\n _SERVICE as SnsRootCanister,\n} from \"../candid/sns_root\";\nimport { idlFactory as certifiedIdlFactory } from \"../candid/sns_root.certified.idl\";\nimport { idlFactory } from \"../candid/sns_root.idl\";\nimport { Canister } from \"./services/canister\";\nimport type { CanisterOptions } from \"./types/canister.options\";\nimport { createServices } from \"./utils/actor.utils\";\n\nexport class RootCanister extends Canister<SnsRootCanister> {\n static create(options: CanisterOptions<SnsRootCanister>) {\n const { service, certifiedService, canisterId } =\n createServices<SnsRootCanister>({\n options,\n idlFactory,\n certifiedIdlFactory,\n });\n\n return new RootCanister(canisterId, service, certifiedService);\n }\n\n /**\n * List and get a summary of the canisters that are part of the Sns.\n *\n * Source code: https://github.com/dfinity/ic/blob/master/rs/sns/root/src/lib.rs\n *\n * @param {Object} params\n * @param {boolean} [params.certified=true] - Query or update calls\n * @param {Principal[]} params.additionalCanisterIds - An optional list of additional canister ids whose status would also have to be requested and added to the returned list\n *\n * @returns {Array<[string, Principal, CanisterStatusResultV2]>} - A list of canisters with type ('root' | 'governance' | 'ledger' | 'dapp' | 'sale'), id and status\n */\n canistersSummary = async ({\n certified = true,\n additionalCanisterIds,\n }: {\n certified?: boolean;\n additionalCanisterIds?: Principal[];\n }): Promise<Array<[string, Principal, CanisterStatusResultV2]>> => {\n /**\n * TODO: candid definition will change soon:\n * - no more additionalCanisterIds param\n * - variant answer\n *\n * type GetSnsCanistersSummaryResponse = record {\n * root : SnsCanisterSummary;\n * swap : SnsCanisterSummary;\n * ledger : SnsCanisterSummary;\n * governance : SnsCanisterSummary;\n * dapps : vec SnsCanisterSummary;\n * archives : vec SnsCanisterSummary;\n * };\n * type SnsCanisterSummary = record {\n * status : CanisterStatusResultV2;\n * principal_id : principal;\n * };\n * service : (SnsRootCanister) -> {\n * get_sns_canisters_summary : () -> (GetSnsCanistersSummaryResponse);\n * }\n */\n\n // TODO(NNS1-1519): Currently support only certified calls - we need query calls for nns-dapp too (as we used both to offer best user experience)\n\n // TODO(NNS1-1487): Swap canister ID is currently not fetched and listed among the results\n return this.caller({ certified }).get_sns_canisters_summary(\n additionalCanisterIds ?? []\n );\n };\n}\n"],
5
+ "mappings": "yFAWO,GAAM,GAAN,aAA2B,EAA0B,CAC1D,MAAO,QAAO,EAA2C,CACvD,GAAM,CAAE,UAAS,mBAAkB,cACjC,EAAgC,CAC9B,UACA,aACA,qBACF,CAAC,EAEH,MAAO,IAAI,GAAa,EAAY,EAAS,CAAgB,CAC/D,CAaA,iBAAmB,MAAO,CACxB,YAAY,GACZ,2BA8BO,KAAK,OAAO,CAAE,WAAU,CAAC,EAAE,0BAChC,GAAyB,CAAC,CAC5B,CAEJ",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ import{a as c}from"./chunk-YL4WAPXH.js";import{a as m}from"./chunk-7F6PCBCJ.js";import{a as d}from"./chunk-LXL5LYD3.js";import{a as l}from"./chunk-WPRZTZWQ.js";var r=class extends Error{},e=(t,n)=>{if(t==null)throw new r(n)};var O=async({agent:t,rootOptions:n,certified:s=!0})=>{let i=d.create({...n,agent:t}),u=await i.canistersSummary({certified:s}),a=f=>u.find(([C,g,S])=>C===f)?.[1],o=a("governance"),p=a("ledger");return e(o),e(p),new l({root:i,governance:c.create({canisterId:o,agent:t}),ledger:m.create({canisterId:p,agent:t}),certified:s})};export{O as a};
2
+ //# sourceMappingURL=chunk-RB6XGLR7.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/asserts.utils.ts", "../../src/sns.ts"],
4
+ "sourcesContent": ["export class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n) => asserts value is NonNullable<T> = <T>(\n value: T,\n message?: string\n): void => {\n if (value === null || value === undefined) {\n throw new NullishError(message);\n }\n};\n", "import type { Agent } from \"@dfinity/agent\";\nimport type { Principal } from \"@dfinity/principal\";\nimport type {\n CanisterStatusResultV2,\n _SERVICE as SnsRootCanister,\n} from \"../candid/sns_root\";\nimport { GovernanceCanister } from \"./governance.canister\";\nimport { LedgerCanister } from \"./ledger.canister\";\nimport { RootCanister } from \"./root.canister\";\nimport { SnsWrapper } from \"./sns.wrapper\";\nimport type { CanisterOptions } from \"./types/canister.options\";\nimport type { QueryParams } from \"./types/query.params\";\nimport { assertNonNullish } from \"./utils/asserts.utils\";\n\n/**\n * Options to discover and initialize all canisters of a Sns.\n */\nexport interface InitSnsCanistersOptions extends QueryParams {\n /** An agent that can be used to override the default agent. Useful to target another environment that mainnet. */\n agent?: Agent;\n /** The options that will be used to instantiate the actors of the root canister of the particular Sns. */\n rootOptions: Omit<CanisterOptions<SnsRootCanister>, \"agent\">;\n}\n\nexport interface InitSns {\n (options: InitSnsCanistersOptions): Promise<SnsWrapper>;\n}\n\n/**\n * Lookup for the canister ids of a Sns and initialize the wrapper to access its features.\n */\nexport const initSns: InitSns = async ({\n agent,\n rootOptions,\n certified = true,\n}: InitSnsCanistersOptions): Promise<SnsWrapper> => {\n const rootCanister: RootCanister = RootCanister.create({\n ...rootOptions,\n agent,\n });\n\n // TODO: this will be soon modified to variants, see canistersSummary details\n const canisters: Array<[string, Principal, CanisterStatusResultV2]> =\n await rootCanister.canistersSummary({ certified });\n\n const canisterId = (\n type: \"governance\" | \"ledger\" | \"swap\"\n ): Principal | undefined =>\n canisters.find(\n /* eslint-disable @typescript-eslint/no-unused-vars */\n ([canisterType, _canisterId, _status]: [\n string,\n Principal,\n CanisterStatusResultV2\n ]) => canisterType === type\n )?.[1];\n\n const governanceCanisterId: Principal | undefined = canisterId(\"governance\");\n const ledgerCanisterId: Principal | undefined = canisterId(\"ledger\");\n\n // TODO: not yet provided, see canistersSummary\n // const swapCanisterId: Principal | undefined = canisterId('swap');\n\n assertNonNullish(governanceCanisterId);\n assertNonNullish(ledgerCanisterId);\n // assert(swapCanisterId);\n\n return new SnsWrapper({\n root: rootCanister,\n governance: GovernanceCanister.create({\n canisterId: governanceCanisterId,\n agent,\n }),\n ledger: LedgerCanister.create({ canisterId: ledgerCanisterId, agent }),\n certified,\n });\n};\n"],
5
+ "mappings": "gKAAO,GAAM,GAAN,aAA2B,MAAM,CAAC,EAE5B,EAG0B,CACrC,EACA,IACS,CACT,GAAI,GAAU,KACZ,KAAM,IAAI,GAAa,CAAO,CAElC,ECmBO,GAAM,GAAmB,MAAO,CACrC,QACA,cACA,YAAY,MACsC,CAClD,GAAM,GAA6B,EAAa,OAAO,CACrD,GAAG,EACH,OACF,CAAC,EAGK,EACJ,KAAM,GAAa,iBAAiB,CAAE,WAAU,CAAC,EAE7C,EAAa,AACjB,GAEA,EAAU,KAER,CAAC,CAAC,EAAc,EAAa,KAIvB,IAAiB,CACzB,IAAI,GAEA,EAA8C,EAAW,YAAY,EACrE,EAA0C,EAAW,QAAQ,EAKnE,SAAiB,CAAoB,EACrC,EAAiB,CAAgB,EAG1B,GAAI,GAAW,CACpB,KAAM,EACN,WAAY,EAAmB,OAAO,CACpC,WAAY,EACZ,OACF,CAAC,EACD,OAAQ,EAAe,OAAO,CAAE,WAAY,EAAkB,OAAM,CAAC,EACrE,WACF,CAAC,CACH",
6
+ "names": []
7
+ }