@sovereign-sdk/modules 0.1.11 → 0.1.12
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 +29 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -16,26 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __async = (__this, __arguments, generator) => {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
var fulfilled = (value) => {
|
|
22
|
-
try {
|
|
23
|
-
step(generator.next(value));
|
|
24
|
-
} catch (e) {
|
|
25
|
-
reject(e);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var rejected = (value) => {
|
|
29
|
-
try {
|
|
30
|
-
step(generator.throw(value));
|
|
31
|
-
} catch (e) {
|
|
32
|
-
reject(e);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
19
|
|
|
40
20
|
// src/index.ts
|
|
41
21
|
var src_exports = {};
|
|
@@ -74,19 +54,17 @@ var Bank = class {
|
|
|
74
54
|
* const tokenBalance = await bank.balance("0x123...", "token_123");
|
|
75
55
|
* ```
|
|
76
56
|
*/
|
|
77
|
-
balance(address, tokenId) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
});
|
|
57
|
+
async balance(address, tokenId) {
|
|
58
|
+
const token = await this.tokenIdOrElseGasTokenId(tokenId);
|
|
59
|
+
try {
|
|
60
|
+
const response = await this.rollup.http.get(
|
|
61
|
+
`/modules/bank/tokens/${token}/balances/${address}`
|
|
62
|
+
);
|
|
63
|
+
return BigInt(response.amount);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
if (this.isMissingAccountError(err)) return BigInt(0);
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
90
68
|
}
|
|
91
69
|
/**
|
|
92
70
|
* Gets the total supply of a specific token.
|
|
@@ -106,14 +84,12 @@ var Bank = class {
|
|
|
106
84
|
* const tokenSupply = await bank.totalSupply("token_123");
|
|
107
85
|
* ```
|
|
108
86
|
*/
|
|
109
|
-
totalSupply(tokenId) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return BigInt(response.amount);
|
|
116
|
-
});
|
|
87
|
+
async totalSupply(tokenId) {
|
|
88
|
+
const token = await this.tokenIdOrElseGasTokenId(tokenId);
|
|
89
|
+
const response = await this.rollup.http.get(
|
|
90
|
+
`/modules/bank/tokens/${token}/total-supply`
|
|
91
|
+
);
|
|
92
|
+
return BigInt(response.amount);
|
|
117
93
|
}
|
|
118
94
|
/**
|
|
119
95
|
* Gets the gas token identifier.
|
|
@@ -129,27 +105,22 @@ var Bank = class {
|
|
|
129
105
|
* console.log(`Gas token ID: ${gasTokenId}`);
|
|
130
106
|
* ```
|
|
131
107
|
*/
|
|
132
|
-
gasTokenId() {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return this._gasTokenId;
|
|
140
|
-
});
|
|
108
|
+
async gasTokenId() {
|
|
109
|
+
if (this._gasTokenId) return this._gasTokenId;
|
|
110
|
+
const response = await this.rollup.http.get(
|
|
111
|
+
"/modules/bank/tokens/gas_token"
|
|
112
|
+
);
|
|
113
|
+
this._gasTokenId = response.token_id;
|
|
114
|
+
return this._gasTokenId;
|
|
141
115
|
}
|
|
142
|
-
tokenIdOrElseGasTokenId(tokenId) {
|
|
143
|
-
return
|
|
144
|
-
return tokenId != null ? tokenId : this.gasTokenId();
|
|
145
|
-
});
|
|
116
|
+
async tokenIdOrElseGasTokenId(tokenId) {
|
|
117
|
+
return tokenId ?? this.gasTokenId();
|
|
146
118
|
}
|
|
147
119
|
// biome-ignore lint/suspicious/noExplicitAny: todo
|
|
148
120
|
isMissingAccountError(anyError) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return ((_a = body == null ? void 0 : body.message) == null ? void 0 : _a.startsWith("Balance")) && ((_b = body == null ? void 0 : body.message) == null ? void 0 : _b.endsWith("not found"));
|
|
121
|
+
if (anyError?.status !== 404) return false;
|
|
122
|
+
const body = anyError?.error;
|
|
123
|
+
return body?.message?.startsWith("Balance") && body?.message?.endsWith("not found");
|
|
153
124
|
}
|
|
154
125
|
};
|
|
155
126
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/bank.ts"],"sourcesContent":["export * from \"./bank\";\n","import { type Rollup, SovereignClient } from \"@sovereign-sdk/web3\";\nimport type { ErrorResponse } 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: BalancePayload = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/balances/${address}`,\n );\n\n return BigInt(response.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: TotalSupplyPayload = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/total-supply`,\n );\n return BigInt(response.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: GasTokenIdPayload = await this.rollup.http.get(\n \"/modules/bank/tokens/gas_token\",\n );\n this._gasTokenId = response.token_id;\n return this._gasTokenId;\n }\n\n private async tokenIdOrElseGasTokenId(tokenId?: string): Promise<string> {\n return tokenId ?? this.gasTokenId();\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: todo\n private isMissingAccountError(anyError: any): boolean {\n if (anyError?.status !== 404) return false;\n const body = anyError?.error as ErrorResponse;\n return (\n body?.message?.startsWith(\"Balance\") &&\n body?.message?.endsWith(\"not found\")\n );\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/bank.ts"],"sourcesContent":["export * from \"./bank\";\n","import { type Rollup, SovereignClient } from \"@sovereign-sdk/web3\";\nimport type { ErrorResponse } 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: BalancePayload = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/balances/${address}`,\n );\n\n return BigInt(response.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: TotalSupplyPayload = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/total-supply`,\n );\n return BigInt(response.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: GasTokenIdPayload = await this.rollup.http.get(\n \"/modules/bank/tokens/gas_token\",\n );\n this._gasTokenId = response.token_id;\n return this._gasTokenId;\n }\n\n private async tokenIdOrElseGasTokenId(tokenId?: string): Promise<string> {\n return tokenId ?? this.gasTokenId();\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: todo\n private isMissingAccountError(anyError: any): boolean {\n if (anyError?.status !== 404) return false;\n const body = anyError?.error as ErrorResponse;\n return (\n body?.message?.startsWith(\"Balance\") &&\n body?.message?.endsWith(\"not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AAA,EAEA,MAAc,wBAAwB,SAAmC;AACvE,WAAO,WAAW,KAAK,WAAW;AAAA,EACpC;AAAA;AAAA,EAGQ,sBAAsB,UAAwB;AACpD,QAAI,UAAU,WAAW,IAAK,QAAO;AACrC,UAAM,OAAO,UAAU;AACvB,WACE,MAAM,SAAS,WAAW,SAAS,KACnC,MAAM,SAAS,SAAS,WAAW;AAAA,EAEvC;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
1
|
// src/bank.ts
|
|
23
2
|
var Bank = class {
|
|
24
3
|
/**
|
|
@@ -49,19 +28,17 @@ var Bank = class {
|
|
|
49
28
|
* const tokenBalance = await bank.balance("0x123...", "token_123");
|
|
50
29
|
* ```
|
|
51
30
|
*/
|
|
52
|
-
balance(address, tokenId) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
});
|
|
31
|
+
async balance(address, tokenId) {
|
|
32
|
+
const token = await this.tokenIdOrElseGasTokenId(tokenId);
|
|
33
|
+
try {
|
|
34
|
+
const response = await this.rollup.http.get(
|
|
35
|
+
`/modules/bank/tokens/${token}/balances/${address}`
|
|
36
|
+
);
|
|
37
|
+
return BigInt(response.amount);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
if (this.isMissingAccountError(err)) return BigInt(0);
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
65
42
|
}
|
|
66
43
|
/**
|
|
67
44
|
* Gets the total supply of a specific token.
|
|
@@ -81,14 +58,12 @@ var Bank = class {
|
|
|
81
58
|
* const tokenSupply = await bank.totalSupply("token_123");
|
|
82
59
|
* ```
|
|
83
60
|
*/
|
|
84
|
-
totalSupply(tokenId) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return BigInt(response.amount);
|
|
91
|
-
});
|
|
61
|
+
async totalSupply(tokenId) {
|
|
62
|
+
const token = await this.tokenIdOrElseGasTokenId(tokenId);
|
|
63
|
+
const response = await this.rollup.http.get(
|
|
64
|
+
`/modules/bank/tokens/${token}/total-supply`
|
|
65
|
+
);
|
|
66
|
+
return BigInt(response.amount);
|
|
92
67
|
}
|
|
93
68
|
/**
|
|
94
69
|
* Gets the gas token identifier.
|
|
@@ -104,27 +79,22 @@ var Bank = class {
|
|
|
104
79
|
* console.log(`Gas token ID: ${gasTokenId}`);
|
|
105
80
|
* ```
|
|
106
81
|
*/
|
|
107
|
-
gasTokenId() {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return this._gasTokenId;
|
|
115
|
-
});
|
|
82
|
+
async gasTokenId() {
|
|
83
|
+
if (this._gasTokenId) return this._gasTokenId;
|
|
84
|
+
const response = await this.rollup.http.get(
|
|
85
|
+
"/modules/bank/tokens/gas_token"
|
|
86
|
+
);
|
|
87
|
+
this._gasTokenId = response.token_id;
|
|
88
|
+
return this._gasTokenId;
|
|
116
89
|
}
|
|
117
|
-
tokenIdOrElseGasTokenId(tokenId) {
|
|
118
|
-
return
|
|
119
|
-
return tokenId != null ? tokenId : this.gasTokenId();
|
|
120
|
-
});
|
|
90
|
+
async tokenIdOrElseGasTokenId(tokenId) {
|
|
91
|
+
return tokenId ?? this.gasTokenId();
|
|
121
92
|
}
|
|
122
93
|
// biome-ignore lint/suspicious/noExplicitAny: todo
|
|
123
94
|
isMissingAccountError(anyError) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return ((_a = body == null ? void 0 : body.message) == null ? void 0 : _a.startsWith("Balance")) && ((_b = body == null ? void 0 : body.message) == null ? void 0 : _b.endsWith("not found"));
|
|
95
|
+
if (anyError?.status !== 404) return false;
|
|
96
|
+
const body = anyError?.error;
|
|
97
|
+
return body?.message?.startsWith("Balance") && body?.message?.endsWith("not found");
|
|
128
98
|
}
|
|
129
99
|
};
|
|
130
100
|
export {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bank.ts"],"sourcesContent":["import { type Rollup, SovereignClient } from \"@sovereign-sdk/web3\";\nimport type { ErrorResponse } 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: BalancePayload = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/balances/${address}`,\n );\n\n return BigInt(response.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: TotalSupplyPayload = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/total-supply`,\n );\n return BigInt(response.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: GasTokenIdPayload = await this.rollup.http.get(\n \"/modules/bank/tokens/gas_token\",\n );\n this._gasTokenId = response.token_id;\n return this._gasTokenId;\n }\n\n private async tokenIdOrElseGasTokenId(tokenId?: string): Promise<string> {\n return tokenId ?? this.gasTokenId();\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: todo\n private isMissingAccountError(anyError: any): boolean {\n if (anyError?.status !== 404) return false;\n const body = anyError?.error as ErrorResponse;\n return (\n body?.message?.startsWith(\"Balance\") &&\n body?.message?.endsWith(\"not found\")\n );\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/bank.ts"],"sourcesContent":["import { type Rollup, SovereignClient } from \"@sovereign-sdk/web3\";\nimport type { ErrorResponse } 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: BalancePayload = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/balances/${address}`,\n );\n\n return BigInt(response.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: TotalSupplyPayload = await this.rollup.http.get(\n `/modules/bank/tokens/${token}/total-supply`,\n );\n return BigInt(response.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: GasTokenIdPayload = await this.rollup.http.get(\n \"/modules/bank/tokens/gas_token\",\n );\n this._gasTokenId = response.token_id;\n return this._gasTokenId;\n }\n\n private async tokenIdOrElseGasTokenId(tokenId?: string): Promise<string> {\n return tokenId ?? this.gasTokenId();\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: todo\n private isMissingAccountError(anyError: any): boolean {\n if (anyError?.status !== 404) return false;\n const body = anyError?.error as ErrorResponse;\n return (\n body?.message?.startsWith(\"Balance\") &&\n body?.message?.endsWith(\"not found\")\n );\n }\n}\n"],"mappings":";AAoBO,IAAM,OAAN,MAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWhB,YAAY,QAA0B;AACpC,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WACE,MAAM,SAAS,WAAW,SAAS,KACnC,MAAM,SAAS,SAAS,WAAW;AAAA,EAEvC;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sovereign-sdk/modules",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "A package providing convenient helpers for interacting with core Sovereign SDK modules",
|
|
5
5
|
"repository": "github:Sovereign-Labs/sovereign-sdk",
|
|
6
6
|
"files": [
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"tsup": "^8.3.0",
|
|
23
23
|
"typescript": "^5.6.3",
|
|
24
24
|
"vitest": "4.0.7",
|
|
25
|
-
"@sovereign-sdk/signers": "^0.5.
|
|
25
|
+
"@sovereign-sdk/signers": "^0.5.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"tsup": "^8.3.0",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@sovereign-sdk/
|
|
36
|
-
"@sovereign-sdk/
|
|
35
|
+
"@sovereign-sdk/utils": "^0.0.4",
|
|
36
|
+
"@sovereign-sdk/web3": "^0.12.4"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsup",
|