@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.mjs CHANGED
@@ -9,9 +9,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
9
9
  // src/main.ts
10
10
  import { WarpChainName } from "@vleap/warps";
11
11
 
12
- // src/WarpFastsetDataLoader.ts
13
- import * as bech323 from "bech32";
14
-
15
12
  // src/helpers/encode.ts
16
13
  var encoder = new TextEncoder();
17
14
  var decoder = new TextDecoder();
@@ -58,7 +55,10 @@ var FastsetClient = class {
58
55
  });
59
56
  }
60
57
  async getAccountInfo(address) {
61
- return this.request(this.proxyUrl, "set_proxy_getAccountInfo", { address });
58
+ return this.request(this.proxyUrl, "set_proxy_getAccountInfo", { address, token_balances_filter: [] });
59
+ }
60
+ async getTokenInfo(tokenIds) {
61
+ return this.request(this.proxyUrl, "set_proxy_getTokenInfo", { tokenIds: [Array.from(tokenIds)] });
62
62
  }
63
63
  async getNextNonce(address) {
64
64
  const addressBytes = typeof address === "string" ? this.addressToBytes(address) : address;
@@ -68,10 +68,10 @@ var FastsetClient = class {
68
68
  addressToBytes(address) {
69
69
  try {
70
70
  const decoded = bech32.bech32m.decode(address);
71
- return Array.from(bech32.bech32m.fromWords(decoded.words));
71
+ return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
72
72
  } catch {
73
73
  const decoded = bech32.bech32.decode(address);
74
- return Array.from(bech32.bech32.fromWords(decoded.words));
74
+ return new Uint8Array(bech32.bech32.fromWords(decoded.words));
75
75
  }
76
76
  }
77
77
  static decodeBech32Address(address) {
@@ -95,6 +95,61 @@ var getConfiguredFastsetClient = (config, chain2) => {
95
95
  return new FastsetClient(proxyUrl);
96
96
  };
97
97
 
98
+ // src/tokens/fastset.ts
99
+ var FastsetTokens = [
100
+ {
101
+ chain: "fastset",
102
+ identifier: "08413efc81f99e5b8e03b852b3756674083110c6b65e6b7836b39a26e3908d3c",
103
+ name: "Ethereum",
104
+ symbol: "ETH",
105
+ decimals: 18,
106
+ logoUrl: "https://assets.coingecko.com/coins/images/279/small/ethereum.png",
107
+ amount: 0n
108
+ },
109
+ {
110
+ chain: "fastset",
111
+ identifier: "0ee63eaa3ff9bf6e1c84a70133c5461e6e06d3787ed93200b924a6b82f0f35ff",
112
+ name: "Bitcoin",
113
+ symbol: "BTC",
114
+ decimals: 8,
115
+ logoUrl: "https://assets.coingecko.com/coins/images/1/small/bitcoin.png",
116
+ amount: 0n
117
+ },
118
+ {
119
+ chain: "fastset",
120
+ identifier: "b69f0d3a4d7609367bd893ee3191e48b3047f2c4ccd21728c2441bcc2154f70c",
121
+ name: "Solana",
122
+ symbol: "SOL",
123
+ decimals: 9,
124
+ logoUrl: "https://assets.coingecko.com/coins/images/4128/small/solana.png",
125
+ amount: 0n
126
+ },
127
+ {
128
+ chain: "fastset",
129
+ identifier: "c83166ed4e5e3ca88f7b2cf0ce2d310fa8c4d2ee2fc90d741f7b2040279b2687",
130
+ name: "USD Coin",
131
+ symbol: "USDC",
132
+ decimals: 6,
133
+ logoUrl: "https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png",
134
+ amount: 0n
135
+ }
136
+ ];
137
+
138
+ // src/tokens.ts
139
+ var KnownTokens = {
140
+ mainnet: FastsetTokens,
141
+ testnet: FastsetTokens,
142
+ devnet: FastsetTokens
143
+ };
144
+ var findKnownTokenBySymbol = (symbol, env = "mainnet") => {
145
+ const tokens = KnownTokens[env] || [];
146
+ return tokens.find((token) => token.symbol === symbol) || null;
147
+ };
148
+ var findKnownTokenById = (id2, env = "mainnet") => {
149
+ const tokens = KnownTokens[env] || [];
150
+ return tokens.find((token) => token.identifier === id2) || null;
151
+ };
152
+
98
153
  // src/WarpFastsetDataLoader.ts
99
154
  var WarpFastsetDataLoader = class {
100
155
  constructor(config, chain2) {
@@ -103,15 +158,14 @@ var WarpFastsetDataLoader = class {
103
158
  this.client = getConfiguredFastsetClient(config, chain2);
104
159
  }
105
160
  async getAccount(address) {
106
- const addressBytes = this.addressToBytes(address);
161
+ const addressBytes = FastsetClient.decodeBech32Address(address);
107
162
  const accountInfo = await this.client.getAccountInfo(addressBytes);
108
163
  return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.result?.balance ?? "0", 16)) };
109
164
  }
110
165
  async getAccountAssets(address) {
111
- const addressBytes = this.addressToBytes(address);
166
+ const addressBytes = FastsetClient.decodeBech32Address(address);
112
167
  const accountInfo = await this.client.getAccountInfo(addressBytes);
113
168
  const assets = [];
114
- console.log("accountInfo", accountInfo);
115
169
  const balance = BigInt(parseInt(accountInfo.result?.balance ?? "0", 16));
116
170
  if (balance > 0n) {
117
171
  assets.push({ ...this.chain.nativeToken, amount: balance });
@@ -119,15 +173,15 @@ var WarpFastsetDataLoader = class {
119
173
  for (const [tokenId, tokenBalance] of accountInfo.result?.token_balance ?? []) {
120
174
  const amount = BigInt(parseInt(tokenBalance, 16));
121
175
  if (amount > 0n) {
122
- const tokenInfo = await this.client.getTokenInfo([tokenId]);
123
- const metadata = tokenInfo.requested_token_metadata[0]?.[1];
176
+ const assetInfo = await this.getAssetInfo(Buffer.from(tokenId).toString("hex"));
177
+ if (!assetInfo) continue;
124
178
  assets.push({
125
179
  chain: this.chain.name,
126
180
  identifier: Buffer.from(tokenId).toString("hex"),
127
- symbol: metadata?.token_name || "UNKNOWN",
128
- name: metadata?.token_name || "Unknown Token",
129
- decimals: metadata?.decimals || 6,
130
- logoUrl: void 0,
181
+ symbol: assetInfo.symbol,
182
+ name: assetInfo.name,
183
+ decimals: assetInfo.decimals,
184
+ logoUrl: assetInfo.logoUrl || "",
131
185
  amount
132
186
  });
133
187
  }
@@ -138,18 +192,18 @@ var WarpFastsetDataLoader = class {
138
192
  if (identifier === this.chain.nativeToken.identifier) {
139
193
  return this.chain.nativeToken;
140
194
  }
141
- const tokenId = Buffer.from(identifier, "hex");
142
- const tokenInfo = await this.client.getTokenInfo([Array.from(tokenId)]);
143
- const metadata = tokenInfo.requested_token_metadata[0]?.[1];
144
- if (!metadata) return null;
195
+ const assetInfo = await this.getAssetInfo(identifier);
196
+ if (!assetInfo) {
197
+ return null;
198
+ }
145
199
  return {
146
200
  chain: this.chain.name,
147
201
  identifier,
148
- symbol: metadata.token_name,
149
- name: metadata.token_name,
150
- decimals: metadata.decimals,
151
- logoUrl: void 0,
152
- amount: BigInt(metadata.total_supply)
202
+ symbol: assetInfo.symbol,
203
+ name: assetInfo.name,
204
+ decimals: assetInfo.decimals,
205
+ logoUrl: assetInfo.logoUrl || null,
206
+ amount: 0n
153
207
  };
154
208
  }
155
209
  async getAction(identifier, awaitCompleted = false) {
@@ -158,18 +212,24 @@ var WarpFastsetDataLoader = class {
158
212
  async getAccountActions(address, options) {
159
213
  return [];
160
214
  }
161
- addressToBytes(address) {
162
- try {
163
- const decoded = bech323.bech32m.decode(address);
164
- return Array.from(bech323.bech32m.fromWords(decoded.words));
165
- } catch {
166
- try {
167
- const decoded = bech323.bech32.decode(address);
168
- return Array.from(bech323.bech32.fromWords(decoded.words));
169
- } catch {
170
- throw new Error(`Invalid FastSet address: ${address}`);
171
- }
215
+ async getAssetInfo(identifier) {
216
+ const knownToken = findKnownTokenById(identifier, this.config.env) || findKnownTokenBySymbol(identifier, this.config.env);
217
+ if (knownToken) {
218
+ return knownToken;
172
219
  }
220
+ const tokenInfo = await this.client.getTokenInfo(hexToUint8Array(identifier));
221
+ const metadata = tokenInfo.result?.requested_token_metadata[0]?.[1];
222
+ if (metadata) {
223
+ return {
224
+ chain: this.chain.name,
225
+ identifier,
226
+ symbol: metadata.token_name,
227
+ name: metadata.token_name,
228
+ decimals: metadata.decimals,
229
+ logoUrl: null
230
+ };
231
+ }
232
+ return null;
173
233
  }
174
234
  };
175
235
 
@@ -2781,7 +2841,6 @@ var WarpFastsetWallet = class {
2781
2841
  const proxyUrl = getProviderUrl2(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
2782
2842
  const response = await this.client.request(proxyUrl, "set_proxy_submitTransaction", submitTxReq);
2783
2843
  if (response.error) throw new Error(`JSON-RPC error ${response.error.code}: ${response.error.message}`);
2784
- console.log("submitTransaction response", response.result);
2785
2844
  return "TODO";
2786
2845
  }
2787
2846
  create(mnemonic) {