@vleap/warps-adapter-fastset 0.1.0-alpha.27 → 0.1.0-alpha.28

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 CHANGED
@@ -42,9 +42,6 @@ module.exports = __toCommonJS(index_exports);
42
42
  // src/main.ts
43
43
  var import_warps6 = require("@vleap/warps");
44
44
 
45
- // src/WarpFastsetDataLoader.ts
46
- var bech323 = __toESM(require("bech32"), 1);
47
-
48
45
  // src/helpers/encode.ts
49
46
  var encoder = new TextEncoder();
50
47
  var decoder = new TextDecoder();
@@ -91,7 +88,10 @@ var FastsetClient = class {
91
88
  });
92
89
  }
93
90
  async getAccountInfo(address) {
94
- return this.request(this.proxyUrl, "set_proxy_getAccountInfo", { address });
91
+ return this.request(this.proxyUrl, "set_proxy_getAccountInfo", { address, token_balances_filter: [] });
92
+ }
93
+ async getTokenInfo(tokenIds) {
94
+ return this.request(this.proxyUrl, "set_proxy_getTokenInfo", { tokenIds: [Array.from(tokenIds)] });
95
95
  }
96
96
  async getNextNonce(address) {
97
97
  const addressBytes = typeof address === "string" ? this.addressToBytes(address) : address;
@@ -101,10 +101,10 @@ var FastsetClient = class {
101
101
  addressToBytes(address) {
102
102
  try {
103
103
  const decoded = bech32.bech32m.decode(address);
104
- return Array.from(bech32.bech32m.fromWords(decoded.words));
104
+ return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
105
105
  } catch {
106
106
  const decoded = bech32.bech32.decode(address);
107
- return Array.from(bech32.bech32.fromWords(decoded.words));
107
+ return new Uint8Array(bech32.bech32.fromWords(decoded.words));
108
108
  }
109
109
  }
110
110
  static decodeBech32Address(address) {
@@ -128,6 +128,61 @@ var getConfiguredFastsetClient = (config, chain2) => {
128
128
  return new FastsetClient(proxyUrl);
129
129
  };
130
130
 
131
+ // src/tokens/fastset.ts
132
+ var FastsetTokens = [
133
+ {
134
+ chain: "fastset",
135
+ identifier: "08413efc81f99e5b8e03b852b3756674083110c6b65e6b7836b39a26e3908d3c",
136
+ name: "Ethereum",
137
+ symbol: "ETH",
138
+ decimals: 18,
139
+ logoUrl: "https://assets.coingecko.com/coins/images/279/small/ethereum.png",
140
+ amount: 0n
141
+ },
142
+ {
143
+ chain: "fastset",
144
+ identifier: "0ee63eaa3ff9bf6e1c84a70133c5461e6e06d3787ed93200b924a6b82f0f35ff",
145
+ name: "Bitcoin",
146
+ symbol: "BTC",
147
+ decimals: 8,
148
+ logoUrl: "https://assets.coingecko.com/coins/images/1/small/bitcoin.png",
149
+ amount: 0n
150
+ },
151
+ {
152
+ chain: "fastset",
153
+ identifier: "b69f0d3a4d7609367bd893ee3191e48b3047f2c4ccd21728c2441bcc2154f70c",
154
+ name: "Solana",
155
+ symbol: "SOL",
156
+ decimals: 9,
157
+ logoUrl: "https://assets.coingecko.com/coins/images/4128/small/solana.png",
158
+ amount: 0n
159
+ },
160
+ {
161
+ chain: "fastset",
162
+ identifier: "c83166ed4e5e3ca88f7b2cf0ce2d310fa8c4d2ee2fc90d741f7b2040279b2687",
163
+ name: "USD Coin",
164
+ symbol: "USDC",
165
+ decimals: 6,
166
+ logoUrl: "https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png",
167
+ amount: 0n
168
+ }
169
+ ];
170
+
171
+ // src/tokens.ts
172
+ var KnownTokens = {
173
+ mainnet: FastsetTokens,
174
+ testnet: FastsetTokens,
175
+ devnet: FastsetTokens
176
+ };
177
+ var findKnownTokenBySymbol = (symbol, env = "mainnet") => {
178
+ const tokens = KnownTokens[env] || [];
179
+ return tokens.find((token) => token.symbol === symbol) || null;
180
+ };
181
+ var findKnownTokenById = (id2, env = "mainnet") => {
182
+ const tokens = KnownTokens[env] || [];
183
+ return tokens.find((token) => token.identifier === id2) || null;
184
+ };
185
+
131
186
  // src/WarpFastsetDataLoader.ts
132
187
  var WarpFastsetDataLoader = class {
133
188
  constructor(config, chain2) {
@@ -136,15 +191,14 @@ var WarpFastsetDataLoader = class {
136
191
  this.client = getConfiguredFastsetClient(config, chain2);
137
192
  }
138
193
  async getAccount(address) {
139
- const addressBytes = this.addressToBytes(address);
194
+ const addressBytes = FastsetClient.decodeBech32Address(address);
140
195
  const accountInfo = await this.client.getAccountInfo(addressBytes);
141
196
  return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.result?.balance ?? "0", 16)) };
142
197
  }
143
198
  async getAccountAssets(address) {
144
- const addressBytes = this.addressToBytes(address);
199
+ const addressBytes = FastsetClient.decodeBech32Address(address);
145
200
  const accountInfo = await this.client.getAccountInfo(addressBytes);
146
201
  const assets = [];
147
- console.log("accountInfo", accountInfo);
148
202
  const balance = BigInt(parseInt(accountInfo.result?.balance ?? "0", 16));
149
203
  if (balance > 0n) {
150
204
  assets.push({ ...this.chain.nativeToken, amount: balance });
@@ -152,15 +206,15 @@ var WarpFastsetDataLoader = class {
152
206
  for (const [tokenId, tokenBalance] of accountInfo.result?.token_balance ?? []) {
153
207
  const amount = BigInt(parseInt(tokenBalance, 16));
154
208
  if (amount > 0n) {
155
- const tokenInfo = await this.client.getTokenInfo([tokenId]);
156
- const metadata = tokenInfo.requested_token_metadata[0]?.[1];
209
+ const assetInfo = await this.getAssetInfo(Buffer.from(tokenId).toString("hex"));
210
+ if (!assetInfo) continue;
157
211
  assets.push({
158
212
  chain: this.chain.name,
159
213
  identifier: Buffer.from(tokenId).toString("hex"),
160
- symbol: metadata?.token_name || "UNKNOWN",
161
- name: metadata?.token_name || "Unknown Token",
162
- decimals: metadata?.decimals || 6,
163
- logoUrl: void 0,
214
+ symbol: assetInfo.symbol,
215
+ name: assetInfo.name,
216
+ decimals: assetInfo.decimals,
217
+ logoUrl: assetInfo.logoUrl || "",
164
218
  amount
165
219
  });
166
220
  }
@@ -171,18 +225,18 @@ var WarpFastsetDataLoader = class {
171
225
  if (identifier === this.chain.nativeToken.identifier) {
172
226
  return this.chain.nativeToken;
173
227
  }
174
- const tokenId = Buffer.from(identifier, "hex");
175
- const tokenInfo = await this.client.getTokenInfo([Array.from(tokenId)]);
176
- const metadata = tokenInfo.requested_token_metadata[0]?.[1];
177
- if (!metadata) return null;
228
+ const assetInfo = await this.getAssetInfo(identifier);
229
+ if (!assetInfo) {
230
+ return null;
231
+ }
178
232
  return {
179
233
  chain: this.chain.name,
180
234
  identifier,
181
- symbol: metadata.token_name,
182
- name: metadata.token_name,
183
- decimals: metadata.decimals,
184
- logoUrl: void 0,
185
- amount: BigInt(metadata.total_supply)
235
+ symbol: assetInfo.symbol,
236
+ name: assetInfo.name,
237
+ decimals: assetInfo.decimals,
238
+ logoUrl: assetInfo.logoUrl || null,
239
+ amount: 0n
186
240
  };
187
241
  }
188
242
  async getAction(identifier, awaitCompleted = false) {
@@ -191,18 +245,24 @@ var WarpFastsetDataLoader = class {
191
245
  async getAccountActions(address, options) {
192
246
  return [];
193
247
  }
194
- addressToBytes(address) {
195
- try {
196
- const decoded = bech323.bech32m.decode(address);
197
- return Array.from(bech323.bech32m.fromWords(decoded.words));
198
- } catch {
199
- try {
200
- const decoded = bech323.bech32.decode(address);
201
- return Array.from(bech323.bech32.fromWords(decoded.words));
202
- } catch {
203
- throw new Error(`Invalid FastSet address: ${address}`);
204
- }
248
+ async getAssetInfo(identifier) {
249
+ const knownToken = findKnownTokenById(identifier, this.config.env) || findKnownTokenBySymbol(identifier, this.config.env);
250
+ if (knownToken) {
251
+ return knownToken;
205
252
  }
253
+ const tokenInfo = await this.client.getTokenInfo(hexToUint8Array(identifier));
254
+ const metadata = tokenInfo.result?.requested_token_metadata[0]?.[1];
255
+ if (metadata) {
256
+ return {
257
+ chain: this.chain.name,
258
+ identifier,
259
+ symbol: metadata.token_name,
260
+ name: metadata.token_name,
261
+ decimals: metadata.decimals,
262
+ logoUrl: null
263
+ };
264
+ }
265
+ return null;
206
266
  }
207
267
  };
208
268
 
@@ -2800,7 +2860,6 @@ var WarpFastsetWallet = class {
2800
2860
  const proxyUrl = (0, import_warps5.getProviderUrl)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
2801
2861
  const response = await this.client.request(proxyUrl, "set_proxy_submitTransaction", submitTxReq);
2802
2862
  if (response.error) throw new Error(`JSON-RPC error ${response.error.code}: ${response.error.message}`);
2803
- console.log("submitTransaction response", response.result);
2804
2863
  return "TODO";
2805
2864
  }
2806
2865
  create(mnemonic) {