@sovereign-sdk/modules 0.0.2 → 0.0.4
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.
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -92,10 +92,9 @@ var Bank = class {
|
|
|
92
92
|
);
|
|
93
93
|
isSuccessResponse(response);
|
|
94
94
|
return BigInt(response.data.amount);
|
|
95
|
-
} catch (
|
|
96
|
-
const err = e;
|
|
95
|
+
} catch (err) {
|
|
97
96
|
if (this.isMissingAccountError(err)) return BigInt(0);
|
|
98
|
-
throw
|
|
97
|
+
throw err;
|
|
99
98
|
}
|
|
100
99
|
});
|
|
101
100
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/bank.ts","../src/types.ts"],"sourcesContent":["export * from \"./bank\";\n","import { type Rollup, SovereignClient } from \"@sovereign-sdk/web3\";\nimport { type ErrorResponse, type Response, isSuccessResponse } from \"./types\";\n\ntype GasTokenIdPayload = {\n token_id: string;\n};\n\ntype BalancePayload = {\n amount: string;\n token_id: string;\n};\n\ntype TotalSupplyPayload = {\n amount: string;\n token_id: string;\n};\n\n/**\n * Bank class for interacting with the Sovereign SDK Bank module.\n */\nexport class Bank {\n // biome-ignore lint/suspicious/noExplicitAny: types arent used\n private readonly rollup: Rollup<any, any>;\n private _gasTokenId?: string;\n\n /**\n * Creates a new Bank instance.\n *\n * @param rollup - The rollup instance to use for HTTP requests\n */\n // biome-ignore lint/suspicious/noExplicitAny: types arent used\n constructor(rollup: Rollup<any, any>) {\n this.rollup = rollup;\n }\n\n /**\n * Gets the balance of a specific token for a given address.\n *\n * If no token ID is provided, the gas token balance will be returned.\n *\n * @param address - The address to query the balance for\n * @param tokenId - Optional token ID. If not provided, uses the gas token\n * @returns Promise resolving to the token balance as a bigint\n * @throws {SovereignClient.APIError} When the request fails for reasons other than missing account\n * @example\n * ```typescript\n * const bank = new Bank(rollup);\n * const balance = await bank.balance(\"0x123...\");\n * console.log(`Balance: ${balance}`);\n *\n * // Query specific token balance\n * const tokenBalance = await bank.balance(\"0x123...\", \"token_123\");\n * ```\n */\n async balance(address: string, tokenId?: string): Promise<bigint> {\n const token = await this.tokenIdOrElseGasTokenId(tokenId);\n\n try {\n const response: Response<BalancePayload> = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/balances/${address}`,\n );\n\n isSuccessResponse(response);\n return BigInt(response.data.amount);\n } catch (
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/bank.ts","../src/types.ts"],"sourcesContent":["export * from \"./bank\";\n","import { type Rollup, SovereignClient } from \"@sovereign-sdk/web3\";\nimport { type ErrorResponse, type Response, isSuccessResponse } from \"./types\";\n\ntype GasTokenIdPayload = {\n token_id: string;\n};\n\ntype BalancePayload = {\n amount: string;\n token_id: string;\n};\n\ntype TotalSupplyPayload = {\n amount: string;\n token_id: string;\n};\n\n/**\n * Bank class for interacting with the Sovereign SDK Bank module.\n */\nexport class Bank {\n // biome-ignore lint/suspicious/noExplicitAny: types arent used\n private readonly rollup: Rollup<any, any>;\n private _gasTokenId?: string;\n\n /**\n * Creates a new Bank instance.\n *\n * @param rollup - The rollup instance to use for HTTP requests\n */\n // biome-ignore lint/suspicious/noExplicitAny: types arent used\n constructor(rollup: Rollup<any, any>) {\n this.rollup = rollup;\n }\n\n /**\n * Gets the balance of a specific token for a given address.\n *\n * If no token ID is provided, the gas token balance will be returned.\n *\n * @param address - The address to query the balance for\n * @param tokenId - Optional token ID. If not provided, uses the gas token\n * @returns Promise resolving to the token balance as a bigint\n * @throws {SovereignClient.APIError} When the request fails for reasons other than missing account\n * @example\n * ```typescript\n * const bank = new Bank(rollup);\n * const balance = await bank.balance(\"0x123...\");\n * console.log(`Balance: ${balance}`);\n *\n * // Query specific token balance\n * const tokenBalance = await bank.balance(\"0x123...\", \"token_123\");\n * ```\n */\n async balance(address: string, tokenId?: string): Promise<bigint> {\n const token = await this.tokenIdOrElseGasTokenId(tokenId);\n\n try {\n const response: Response<BalancePayload> = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/balances/${address}`,\n );\n\n isSuccessResponse(response);\n return BigInt(response.data.amount);\n } catch (err) {\n if (this.isMissingAccountError(err)) return BigInt(0);\n\n throw err;\n }\n }\n\n /**\n * Gets the total supply of a specific token.\n *\n * If no token ID is provided, returns the total supply of the gas token.\n *\n * @param tokenId - Optional token ID. If not provided, uses the gas token\n * @returns Promise resolving to the total supply as a bigint\n * @throws {SovereignClient.APIError} When the request fails\n * @example\n * ```typescript\n * const bank = new Bank(rollup);\n * const totalSupply = await bank.totalSupply();\n * console.log(`Total gas token supply: ${totalSupply}`);\n *\n * // Query specific token supply\n * const tokenSupply = await bank.totalSupply(\"token_123\");\n * ```\n */\n async totalSupply(tokenId?: string): Promise<bigint> {\n const token = await this.tokenIdOrElseGasTokenId(tokenId);\n const response: Response<TotalSupplyPayload> = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/total-supply`,\n );\n isSuccessResponse(response);\n return BigInt(response.data.amount);\n }\n\n /**\n * Gets the gas token identifier.\n *\n * The gas token ID is cached after the first request to avoid repeated API calls.\n *\n * @returns Promise resolving to the gas token ID as a string\n * @throws {Error} When the gas token ID cannot be retrieved\n * @example\n * ```typescript\n * const bank = new Bank(rollup);\n * const gasTokenId = await bank.gasTokenId();\n * console.log(`Gas token ID: ${gasTokenId}`);\n * ```\n */\n async gasTokenId(): Promise<string> {\n if (this._gasTokenId) return this._gasTokenId;\n const response: Response<GasTokenIdPayload> = await this.rollup.http.get(\n \"/modules/bank/tokens/gas_token\",\n );\n isSuccessResponse(response);\n this._gasTokenId = response.data.token_id;\n return this._gasTokenId;\n }\n\n private async tokenIdOrElseGasTokenId(tokenId?: string): Promise<string> {\n return tokenId ?? this.gasTokenId();\n }\n\n private isMissingAccountError(anyError: unknown): boolean {\n if (!(anyError instanceof SovereignClient.APIError)) return false;\n if (anyError.status !== 404) return false;\n const body = anyError.error as ErrorResponse;\n const error = body.errors[0];\n if (!error) return false;\n return (\n error.title.startsWith(\"Balance\") && error.title.endsWith(\"not found\")\n );\n }\n}\n","export type SuccessResponse<T> = {\n data: T;\n};\n\nexport type ErrorResponse = {\n data: undefined;\n errors: {\n status: number;\n title: string;\n details: Record<string, unknown>;\n }[];\n};\n\nexport type Response<T> = SuccessResponse<T> | ErrorResponse;\n\nexport function isSuccessResponse<T>(\n response: Response<T>,\n): asserts response is SuccessResponse<T> {\n if (response.data === undefined)\n throw new Error(\"data field missing from response\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA6C;;;ACetC,SAAS,kBACd,UACwC;AACxC,MAAI,SAAS,SAAS;AACpB,UAAM,IAAI,MAAM,kCAAkC;AACtD;;;ADAO,IAAM,OAAN,MAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWhB,YAAY,QAA0B;AACpC,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBM,QAAQ,SAAiB,SAAmC;AAAA;AAChE,YAAM,QAAQ,MAAM,KAAK,wBAAwB,OAAO;AAExD,UAAI;AACF,cAAM,WAAqC,MAAM,KAAK,OAAO,KAAK;AAAA,UAChE,wBAAwB,KAAK,aAAa,OAAO;AAAA,QACnD;AAEA,0BAAkB,QAAQ;AAC1B,eAAO,OAAO,SAAS,KAAK,MAAM;AAAA,MACpC,SAAS,KAAK;AACZ,YAAI,KAAK,sBAAsB,GAAG,EAAG,QAAO,OAAO,CAAC;AAEpD,cAAM;AAAA,MACR;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBM,YAAY,SAAmC;AAAA;AACnD,YAAM,QAAQ,MAAM,KAAK,wBAAwB,OAAO;AACxD,YAAM,WAAyC,MAAM,KAAK,OAAO,KAAK;AAAA,QACpE,wBAAwB,KAAK;AAAA,MAC/B;AACA,wBAAkB,QAAQ;AAC1B,aAAO,OAAO,SAAS,KAAK,MAAM;AAAA,IACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBM,aAA8B;AAAA;AAClC,UAAI,KAAK,YAAa,QAAO,KAAK;AAClC,YAAM,WAAwC,MAAM,KAAK,OAAO,KAAK;AAAA,QACnE;AAAA,MACF;AACA,wBAAkB,QAAQ;AAC1B,WAAK,cAAc,SAAS,KAAK;AACjC,aAAO,KAAK;AAAA,IACd;AAAA;AAAA,EAEc,wBAAwB,SAAmC;AAAA;AACvE,aAAO,4BAAW,KAAK,WAAW;AAAA,IACpC;AAAA;AAAA,EAEQ,sBAAsB,UAA4B;AACxD,QAAI,EAAE,oBAAoB,4BAAgB,UAAW,QAAO;AAC5D,QAAI,SAAS,WAAW,IAAK,QAAO;AACpC,UAAM,OAAO,SAAS;AACtB,UAAM,QAAQ,KAAK,OAAO,CAAC;AAC3B,QAAI,CAAC,MAAO,QAAO;AACnB,WACE,MAAM,MAAM,WAAW,SAAS,KAAK,MAAM,MAAM,SAAS,WAAW;AAAA,EAEzE;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -67,10 +67,9 @@ var Bank = class {
|
|
|
67
67
|
);
|
|
68
68
|
isSuccessResponse(response);
|
|
69
69
|
return BigInt(response.data.amount);
|
|
70
|
-
} catch (
|
|
71
|
-
const err = e;
|
|
70
|
+
} catch (err) {
|
|
72
71
|
if (this.isMissingAccountError(err)) return BigInt(0);
|
|
73
|
-
throw
|
|
72
|
+
throw err;
|
|
74
73
|
}
|
|
75
74
|
});
|
|
76
75
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bank.ts","../src/types.ts"],"sourcesContent":["import { type Rollup, SovereignClient } from \"@sovereign-sdk/web3\";\nimport { type ErrorResponse, type Response, isSuccessResponse } from \"./types\";\n\ntype GasTokenIdPayload = {\n token_id: string;\n};\n\ntype BalancePayload = {\n amount: string;\n token_id: string;\n};\n\ntype TotalSupplyPayload = {\n amount: string;\n token_id: string;\n};\n\n/**\n * Bank class for interacting with the Sovereign SDK Bank module.\n */\nexport class Bank {\n // biome-ignore lint/suspicious/noExplicitAny: types arent used\n private readonly rollup: Rollup<any, any>;\n private _gasTokenId?: string;\n\n /**\n * Creates a new Bank instance.\n *\n * @param rollup - The rollup instance to use for HTTP requests\n */\n // biome-ignore lint/suspicious/noExplicitAny: types arent used\n constructor(rollup: Rollup<any, any>) {\n this.rollup = rollup;\n }\n\n /**\n * Gets the balance of a specific token for a given address.\n *\n * If no token ID is provided, the gas token balance will be returned.\n *\n * @param address - The address to query the balance for\n * @param tokenId - Optional token ID. If not provided, uses the gas token\n * @returns Promise resolving to the token balance as a bigint\n * @throws {SovereignClient.APIError} When the request fails for reasons other than missing account\n * @example\n * ```typescript\n * const bank = new Bank(rollup);\n * const balance = await bank.balance(\"0x123...\");\n * console.log(`Balance: ${balance}`);\n *\n * // Query specific token balance\n * const tokenBalance = await bank.balance(\"0x123...\", \"token_123\");\n * ```\n */\n async balance(address: string, tokenId?: string): Promise<bigint> {\n const token = await this.tokenIdOrElseGasTokenId(tokenId);\n\n try {\n const response: Response<BalancePayload> = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/balances/${address}`,\n );\n\n isSuccessResponse(response);\n return BigInt(response.data.amount);\n } catch (
|
|
1
|
+
{"version":3,"sources":["../src/bank.ts","../src/types.ts"],"sourcesContent":["import { type Rollup, SovereignClient } from \"@sovereign-sdk/web3\";\nimport { type ErrorResponse, type Response, isSuccessResponse } from \"./types\";\n\ntype GasTokenIdPayload = {\n token_id: string;\n};\n\ntype BalancePayload = {\n amount: string;\n token_id: string;\n};\n\ntype TotalSupplyPayload = {\n amount: string;\n token_id: string;\n};\n\n/**\n * Bank class for interacting with the Sovereign SDK Bank module.\n */\nexport class Bank {\n // biome-ignore lint/suspicious/noExplicitAny: types arent used\n private readonly rollup: Rollup<any, any>;\n private _gasTokenId?: string;\n\n /**\n * Creates a new Bank instance.\n *\n * @param rollup - The rollup instance to use for HTTP requests\n */\n // biome-ignore lint/suspicious/noExplicitAny: types arent used\n constructor(rollup: Rollup<any, any>) {\n this.rollup = rollup;\n }\n\n /**\n * Gets the balance of a specific token for a given address.\n *\n * If no token ID is provided, the gas token balance will be returned.\n *\n * @param address - The address to query the balance for\n * @param tokenId - Optional token ID. If not provided, uses the gas token\n * @returns Promise resolving to the token balance as a bigint\n * @throws {SovereignClient.APIError} When the request fails for reasons other than missing account\n * @example\n * ```typescript\n * const bank = new Bank(rollup);\n * const balance = await bank.balance(\"0x123...\");\n * console.log(`Balance: ${balance}`);\n *\n * // Query specific token balance\n * const tokenBalance = await bank.balance(\"0x123...\", \"token_123\");\n * ```\n */\n async balance(address: string, tokenId?: string): Promise<bigint> {\n const token = await this.tokenIdOrElseGasTokenId(tokenId);\n\n try {\n const response: Response<BalancePayload> = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/balances/${address}`,\n );\n\n isSuccessResponse(response);\n return BigInt(response.data.amount);\n } catch (err) {\n if (this.isMissingAccountError(err)) return BigInt(0);\n\n throw err;\n }\n }\n\n /**\n * Gets the total supply of a specific token.\n *\n * If no token ID is provided, returns the total supply of the gas token.\n *\n * @param tokenId - Optional token ID. If not provided, uses the gas token\n * @returns Promise resolving to the total supply as a bigint\n * @throws {SovereignClient.APIError} When the request fails\n * @example\n * ```typescript\n * const bank = new Bank(rollup);\n * const totalSupply = await bank.totalSupply();\n * console.log(`Total gas token supply: ${totalSupply}`);\n *\n * // Query specific token supply\n * const tokenSupply = await bank.totalSupply(\"token_123\");\n * ```\n */\n async totalSupply(tokenId?: string): Promise<bigint> {\n const token = await this.tokenIdOrElseGasTokenId(tokenId);\n const response: Response<TotalSupplyPayload> = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/total-supply`,\n );\n isSuccessResponse(response);\n return BigInt(response.data.amount);\n }\n\n /**\n * Gets the gas token identifier.\n *\n * The gas token ID is cached after the first request to avoid repeated API calls.\n *\n * @returns Promise resolving to the gas token ID as a string\n * @throws {Error} When the gas token ID cannot be retrieved\n * @example\n * ```typescript\n * const bank = new Bank(rollup);\n * const gasTokenId = await bank.gasTokenId();\n * console.log(`Gas token ID: ${gasTokenId}`);\n * ```\n */\n async gasTokenId(): Promise<string> {\n if (this._gasTokenId) return this._gasTokenId;\n const response: Response<GasTokenIdPayload> = await this.rollup.http.get(\n \"/modules/bank/tokens/gas_token\",\n );\n isSuccessResponse(response);\n this._gasTokenId = response.data.token_id;\n return this._gasTokenId;\n }\n\n private async tokenIdOrElseGasTokenId(tokenId?: string): Promise<string> {\n return tokenId ?? this.gasTokenId();\n }\n\n private isMissingAccountError(anyError: unknown): boolean {\n if (!(anyError instanceof SovereignClient.APIError)) return false;\n if (anyError.status !== 404) return false;\n const body = anyError.error as ErrorResponse;\n const error = body.errors[0];\n if (!error) return false;\n return (\n error.title.startsWith(\"Balance\") && error.title.endsWith(\"not found\")\n );\n }\n}\n","export type SuccessResponse<T> = {\n data: T;\n};\n\nexport type ErrorResponse = {\n data: undefined;\n errors: {\n status: number;\n title: string;\n details: Record<string, unknown>;\n }[];\n};\n\nexport type Response<T> = SuccessResponse<T> | ErrorResponse;\n\nexport function isSuccessResponse<T>(\n response: Response<T>,\n): asserts response is SuccessResponse<T> {\n if (response.data === undefined)\n throw new Error(\"data field missing from response\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAsB,uBAAuB;;;ACetC,S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AAAA,MACF;AACA,wBAAkB,QAAQ;AAC1B,WAAK,cAAc,SAAS,KAAK;AACjC,aAAO,KAAK;AAAA,IACd;AAAA;AAAA,EAEc,wBAAwB,SAAmC;AAAA;AACvE,aAAO,4BAAW,KAAK,WAAW;AAAA,IACpC;AAAA;AAAA,EAEQ,sBAAsB,UAA4B;AACxD,QAAI,EAAE,oBAAoB,gBAAgB,UAAW,QAAO;AAC5D,QAAI,SAAS,WAAW,IAAK,QAAO;AACpC,UAAM,OAAO,SAAS;AACtB,UAAM,QAAQ,KAAK,OAAO,CAAC;AAC3B,QAAI,CAAC,MAAO,QAAO;AACnB,WACE,MAAM,MAAM,WAAW,SAAS,KAAK,MAAM,MAAM,SAAS,WAAW;AAAA,EAEzE;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sovereign-sdk/modules",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "A package providing convenient helpers for interacting with core Sovereign SDK modules",
|
|
5
5
|
"repository": "github:Sovereign-Labs/sovereign-sdk-web3-js",
|
|
6
6
|
"files": [
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@sovereign-sdk/web3": "^0.
|
|
34
|
+
"@sovereign-sdk/web3": "^0.5.1",
|
|
35
35
|
"@sovereign-sdk/utils": "^0.0.3"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|