tapimo 0.1.0 → 0.3.0
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/README.md +57 -16
- package/dist/ApiKey.d.ts +4 -1
- package/dist/ApiKey.d.ts.map +1 -1
- package/dist/ApiKey.js +6 -2
- package/dist/ApiKey.js.map +1 -1
- package/dist/ApiKeys.d.ts +98 -3
- package/dist/ApiKeys.d.ts.map +1 -1
- package/dist/ApiKeys.js +150 -1
- package/dist/ApiKeys.js.map +1 -1
- package/dist/App.d.ts +7917 -2315
- package/dist/App.d.ts.map +1 -1
- package/dist/App.js +141 -329
- package/dist/App.js.map +1 -1
- package/dist/Scope.d.ts +20 -4
- package/dist/Scope.d.ts.map +1 -1
- package/dist/Scope.js +23 -4
- package/dist/Scope.js.map +1 -1
- package/dist/Webhooks.d.ts +2 -2
- package/dist/Webhooks.d.ts.map +1 -1
- package/dist/Webhooks.js +2 -2
- package/dist/Webhooks.js.map +1 -1
- package/dist/admin/App.d.ts +203 -120
- package/dist/admin/App.d.ts.map +1 -1
- package/dist/admin/apps/api-keys.d.ts +111 -6
- package/dist/admin/apps/api-keys.d.ts.map +1 -1
- package/dist/admin/apps/api-keys.js +67 -0
- package/dist/admin/apps/api-keys.js.map +1 -1
- package/dist/admin/apps/scopes.d.ts +12 -1
- package/dist/admin/apps/scopes.d.ts.map +1 -1
- package/dist/admin/apps/scopes.js +3 -0
- package/dist/admin/apps/scopes.js.map +1 -1
- package/dist/admin/apps/verified-tokens.d.ts +116 -116
- package/dist/admin/apps/verified-tokens.js +1 -1
- package/dist/admin/apps/verified-tokens.js.map +1 -1
- package/dist/admin/ui.generated.d.ts +1 -1
- package/dist/admin/ui.generated.js +13 -13
- package/dist/admin/ui.generated.js.map +1 -1
- package/dist/analytics/Analytics.d.ts +151 -0
- package/dist/analytics/Analytics.d.ts.map +1 -0
- package/dist/analytics/Analytics.js +212 -0
- package/dist/analytics/Analytics.js.map +1 -0
- package/dist/analytics/tables/requestEvents.d.ts +215 -0
- package/dist/analytics/tables/requestEvents.d.ts.map +1 -0
- package/dist/analytics/tables/requestEvents.js +264 -0
- package/dist/analytics/tables/requestEvents.js.map +1 -0
- package/dist/apps/data/App.d.ts +19576 -0
- package/dist/apps/data/App.d.ts.map +1 -0
- package/dist/apps/data/App.js +272 -0
- package/dist/apps/data/App.js.map +1 -0
- package/dist/apps/data/index.d.ts +3 -0
- package/dist/apps/data/index.d.ts.map +1 -0
- package/dist/apps/data/index.js +3 -0
- package/dist/apps/data/index.js.map +1 -0
- package/dist/apps/{activities.d.ts → data/routes/activities.d.ts} +32 -32
- package/dist/apps/{activities.d.ts.map → data/routes/activities.d.ts.map} +1 -1
- package/dist/apps/{activities.js → data/routes/activities.js} +13 -13
- package/dist/apps/data/routes/activities.js.map +1 -0
- package/dist/apps/{addresses.d.ts → data/routes/addresses.d.ts} +22 -22
- package/dist/apps/{addresses.d.ts.map → data/routes/addresses.d.ts.map} +1 -1
- package/dist/apps/{addresses.js → data/routes/addresses.js} +5 -5
- package/dist/apps/data/routes/addresses.js.map +1 -0
- package/dist/apps/{balances.d.ts → data/routes/balances.d.ts} +4 -4
- package/dist/apps/data/routes/balances.d.ts.map +1 -0
- package/dist/apps/{balances.js → data/routes/balances.js} +42 -11
- package/dist/apps/data/routes/balances.js.map +1 -0
- package/dist/apps/{blocks.d.ts → data/routes/blocks.d.ts} +47 -47
- package/dist/apps/data/routes/blocks.d.ts.map +1 -0
- package/dist/apps/{blocks.js → data/routes/blocks.js} +13 -13
- package/dist/apps/data/routes/blocks.js.map +1 -0
- package/dist/apps/{coingecko.d.ts → data/routes/coingecko.d.ts} +8 -8
- package/dist/apps/data/routes/coingecko.d.ts.map +1 -0
- package/dist/apps/{coingecko.js → data/routes/coingecko.js} +13 -13
- package/dist/apps/data/routes/coingecko.js.map +1 -0
- package/dist/apps/{exchanges.d.ts → data/routes/exchanges.d.ts} +108 -108
- package/dist/apps/data/routes/exchanges.d.ts.map +1 -0
- package/dist/apps/{exchanges.js → data/routes/exchanges.js} +19 -19
- package/dist/apps/data/routes/exchanges.js.map +1 -0
- package/dist/apps/{fee-amm.d.ts → data/routes/fee-amm.d.ts} +39 -39
- package/dist/apps/data/routes/fee-amm.d.ts.map +1 -0
- package/dist/apps/{fee-amm.js → data/routes/fee-amm.js} +17 -17
- package/dist/apps/data/routes/fee-amm.js.map +1 -0
- package/dist/apps/data/routes/funding.d.ts +765 -0
- package/dist/apps/data/routes/funding.d.ts.map +1 -0
- package/dist/apps/data/routes/funding.js +383 -0
- package/dist/apps/data/routes/funding.js.map +1 -0
- package/dist/apps/{indexer.d.ts → data/routes/indexer.d.ts} +4 -4
- package/dist/apps/data/routes/indexer.d.ts.map +1 -0
- package/dist/apps/{indexer.js → data/routes/indexer.js} +13 -9
- package/dist/apps/data/routes/indexer.js.map +1 -0
- package/dist/apps/{receipts.d.ts → data/routes/receipts.d.ts} +49 -49
- package/dist/apps/data/routes/receipts.d.ts.map +1 -0
- package/dist/apps/{receipts.js → data/routes/receipts.js} +14 -20
- package/dist/apps/data/routes/receipts.js.map +1 -0
- package/dist/apps/{rpc.d.ts → data/routes/rpc.d.ts} +33 -40
- package/dist/apps/data/routes/rpc.d.ts.map +1 -0
- package/dist/apps/{rpc.js → data/routes/rpc.js} +35 -7
- package/dist/apps/data/routes/rpc.js.map +1 -0
- package/dist/apps/{tokenlist.d.ts → data/routes/tokenlist.d.ts} +40 -40
- package/dist/apps/data/routes/tokenlist.d.ts.map +1 -0
- package/dist/apps/{tokenlist.js → data/routes/tokenlist.js} +8 -8
- package/dist/apps/data/routes/tokenlist.js.map +1 -0
- package/dist/apps/{tokens.d.ts → data/routes/tokens.d.ts} +468 -468
- package/dist/apps/data/routes/tokens.d.ts.map +1 -0
- package/dist/apps/{tokens.js → data/routes/tokens.js} +19 -19
- package/dist/apps/data/routes/tokens.js.map +1 -0
- package/dist/apps/{transactions.d.ts → data/routes/transactions.d.ts} +304 -304
- package/dist/apps/data/routes/transactions.d.ts.map +1 -0
- package/dist/apps/{transactions.js → data/routes/transactions.js} +13 -13
- package/dist/apps/data/routes/transactions.js.map +1 -0
- package/dist/apps/{transfers.d.ts → data/routes/transfers.d.ts} +62 -62
- package/dist/apps/data/routes/transfers.d.ts.map +1 -0
- package/dist/apps/{transfers.js → data/routes/transfers.js} +13 -13
- package/dist/apps/data/routes/transfers.js.map +1 -0
- package/dist/apps/{verified-tokens.d.ts → data/routes/verified-tokens.d.ts} +6 -6
- package/dist/apps/data/routes/verified-tokens.d.ts.map +1 -0
- package/dist/apps/{verified-tokens.js → data/routes/verified-tokens.js} +9 -9
- package/dist/apps/data/routes/verified-tokens.js.map +1 -0
- package/dist/apps/{webhooks.d.ts → data/routes/webhooks.d.ts} +17 -17
- package/dist/apps/{webhooks.d.ts.map → data/routes/webhooks.d.ts.map} +1 -1
- package/dist/apps/{webhooks.js → data/routes/webhooks.js} +38 -34
- package/dist/apps/data/routes/webhooks.js.map +1 -0
- package/dist/apps/docs/App.d.ts +29 -0
- package/dist/apps/docs/App.d.ts.map +1 -0
- package/dist/apps/docs/App.js +54 -0
- package/dist/apps/docs/App.js.map +1 -0
- package/dist/{internal/OpenApi.fonts.d.ts → apps/docs/fonts.d.ts} +1 -1
- package/dist/apps/docs/fonts.d.ts.map +1 -0
- package/dist/{internal/OpenApi.fonts.js → apps/docs/fonts.js} +1 -1
- package/dist/apps/docs/fonts.js.map +1 -0
- package/dist/apps/docs/index.d.ts +2 -0
- package/dist/apps/docs/index.d.ts.map +1 -0
- package/dist/apps/docs/index.js +2 -0
- package/dist/apps/docs/index.js.map +1 -0
- package/dist/{internal/OpenApi.logo.d.ts → apps/docs/logo.d.ts} +1 -1
- package/dist/apps/docs/logo.d.ts.map +1 -0
- package/dist/{internal/OpenApi.logo.js → apps/docs/logo.js} +1 -1
- package/dist/apps/docs/logo.js.map +1 -0
- package/dist/apps/docs/reference.d.ts +21 -0
- package/dist/apps/docs/reference.d.ts.map +1 -0
- package/dist/apps/docs/reference.js +112 -0
- package/dist/apps/docs/reference.js.map +1 -0
- package/dist/apps/index.d.ts +5 -0
- package/dist/apps/index.d.ts.map +1 -0
- package/dist/apps/index.js +5 -0
- package/dist/apps/index.js.map +1 -0
- package/dist/apps/mcp.d.ts +76 -0
- package/dist/apps/mcp.d.ts.map +1 -0
- package/dist/apps/mcp.js +188 -0
- package/dist/apps/mcp.js.map +1 -0
- package/dist/apps/metadata.d.ts +7 -0
- package/dist/apps/metadata.d.ts.map +1 -0
- package/dist/apps/metadata.js +15 -0
- package/dist/apps/metadata.js.map +1 -0
- package/dist/apps/platform/App.d.ts +5262 -0
- package/dist/apps/platform/App.d.ts.map +1 -0
- package/dist/apps/platform/App.js +84 -0
- package/dist/apps/platform/App.js.map +1 -0
- package/dist/apps/platform/Billing.d.ts +279 -0
- package/dist/apps/platform/Billing.d.ts.map +1 -0
- package/dist/apps/platform/Billing.js +477 -0
- package/dist/apps/platform/Billing.js.map +1 -0
- package/dist/apps/platform/index.d.ts +3 -0
- package/dist/apps/platform/index.d.ts.map +1 -0
- package/dist/apps/platform/index.js +3 -0
- package/dist/apps/platform/index.js.map +1 -0
- package/dist/apps/platform/routes/api-keys.d.ts +973 -0
- package/dist/apps/platform/routes/api-keys.d.ts.map +1 -0
- package/dist/apps/platform/routes/api-keys.js +430 -0
- package/dist/apps/platform/routes/api-keys.js.map +1 -0
- package/dist/apps/platform/routes/billing.d.ts +1520 -0
- package/dist/apps/platform/routes/billing.d.ts.map +1 -0
- package/dist/apps/platform/routes/billing.js +795 -0
- package/dist/apps/platform/routes/billing.js.map +1 -0
- package/dist/apps/platform/routes/invitations.d.ts +851 -0
- package/dist/apps/platform/routes/invitations.d.ts.map +1 -0
- package/dist/apps/platform/routes/invitations.js +471 -0
- package/dist/apps/platform/routes/invitations.js.map +1 -0
- package/dist/apps/platform/routes/me.d.ts +95 -0
- package/dist/apps/platform/routes/me.d.ts.map +1 -0
- package/dist/apps/platform/routes/me.js +81 -0
- package/dist/apps/platform/routes/me.js.map +1 -0
- package/dist/apps/platform/routes/members.d.ts +554 -0
- package/dist/apps/platform/routes/members.d.ts.map +1 -0
- package/dist/apps/platform/routes/members.js +251 -0
- package/dist/apps/platform/routes/members.js.map +1 -0
- package/dist/apps/platform/routes/orgs.d.ts +596 -0
- package/dist/apps/platform/routes/orgs.d.ts.map +1 -0
- package/dist/apps/platform/routes/orgs.js +276 -0
- package/dist/apps/platform/routes/orgs.js.map +1 -0
- package/dist/apps/platform/routes/projects.d.ts +740 -0
- package/dist/apps/platform/routes/projects.d.ts.map +1 -0
- package/dist/apps/platform/routes/projects.js +286 -0
- package/dist/apps/platform/routes/projects.js.map +1 -0
- package/dist/apps/platform/routes/scopes.d.ts +107 -0
- package/dist/apps/platform/routes/scopes.d.ts.map +1 -0
- package/dist/apps/platform/routes/scopes.js +66 -0
- package/dist/apps/platform/routes/scopes.js.map +1 -0
- package/dist/apps/platform/routes/usage.d.ts +588 -0
- package/dist/apps/platform/routes/usage.d.ts.map +1 -0
- package/dist/apps/platform/routes/usage.js +391 -0
- package/dist/apps/platform/routes/usage.js.map +1 -0
- package/dist/apps/relay/App.d.ts +44 -0
- package/dist/apps/relay/App.d.ts.map +1 -0
- package/dist/apps/relay/App.js +211 -0
- package/dist/apps/relay/App.js.map +1 -0
- package/dist/apps/relay/Sponsorships.d.ts +107 -0
- package/dist/apps/relay/Sponsorships.d.ts.map +1 -0
- package/dist/apps/relay/Sponsorships.js +194 -0
- package/dist/apps/relay/Sponsorships.js.map +1 -0
- package/dist/apps/relay/index.d.ts +3 -0
- package/dist/apps/relay/index.d.ts.map +1 -0
- package/dist/apps/relay/index.js +3 -0
- package/dist/apps/relay/index.js.map +1 -0
- package/dist/cli/Cli.d.ts +9 -2
- package/dist/cli/Cli.d.ts.map +1 -1
- package/dist/cli/Cli.js +12 -4
- package/dist/cli/Cli.js.map +1 -1
- package/dist/cli/commands/admin.d.ts +5 -1
- package/dist/cli/commands/admin.d.ts.map +1 -1
- package/dist/cli/commands/admin.js +82 -3
- package/dist/cli/commands/admin.js.map +1 -1
- package/dist/db/Db.d.ts +17 -0
- package/dist/db/Db.d.ts.map +1 -1
- package/dist/db/Db.js +254 -0
- package/dist/db/Db.js.map +1 -1
- package/dist/db/Schema.d.ts +159 -0
- package/dist/db/Schema.d.ts.map +1 -1
- package/dist/db/Schema.js +187 -2
- package/dist/db/Schema.js.map +1 -1
- package/dist/db/tables/billingSettings.d.ts +55 -0
- package/dist/db/tables/billingSettings.d.ts.map +1 -0
- package/dist/db/tables/billingSettings.js +70 -0
- package/dist/db/tables/billingSettings.js.map +1 -0
- package/dist/db/tables/invitations.d.ts +84 -0
- package/dist/db/tables/invitations.d.ts.map +1 -0
- package/dist/db/tables/invitations.js +165 -0
- package/dist/db/tables/invitations.js.map +1 -0
- package/dist/db/tables/memberships.d.ts +108 -0
- package/dist/db/tables/memberships.d.ts.map +1 -0
- package/dist/db/tables/memberships.js +153 -0
- package/dist/db/tables/memberships.js.map +1 -0
- package/dist/db/tables/organizations.d.ts +48 -0
- package/dist/db/tables/organizations.d.ts.map +1 -1
- package/dist/db/tables/organizations.js +97 -2
- package/dist/db/tables/organizations.js.map +1 -1
- package/dist/db/tables/projects.d.ts +65 -0
- package/dist/db/tables/projects.d.ts.map +1 -0
- package/dist/db/tables/projects.js +75 -0
- package/dist/db/tables/projects.js.map +1 -0
- package/dist/db/tables/requestUsage.d.ts +121 -0
- package/dist/db/tables/requestUsage.d.ts.map +1 -0
- package/dist/db/tables/requestUsage.js +150 -0
- package/dist/db/tables/requestUsage.js.map +1 -0
- package/dist/db/tables/sponsoredTransactions.d.ts +239 -0
- package/dist/db/tables/sponsoredTransactions.d.ts.map +1 -0
- package/dist/db/tables/sponsoredTransactions.js +314 -0
- package/dist/db/tables/sponsoredTransactions.js.map +1 -0
- package/dist/db/tables/stripeCustomers.d.ts +81 -0
- package/dist/db/tables/stripeCustomers.d.ts.map +1 -0
- package/dist/db/tables/stripeCustomers.js +120 -0
- package/dist/db/tables/stripeCustomers.js.map +1 -0
- package/dist/db/tables/users.d.ts +48 -0
- package/dist/db/tables/users.d.ts.map +1 -0
- package/dist/db/tables/users.js +65 -0
- package/dist/db/tables/users.js.map +1 -0
- package/dist/handlers/internal/executionError.d.ts.map +1 -1
- package/dist/handlers/internal/executionError.js +2 -0
- package/dist/handlers/internal/executionError.js.map +1 -1
- package/dist/handlers/internal/multisig.d.ts +2 -6
- package/dist/handlers/internal/multisig.d.ts.map +1 -1
- package/dist/handlers/internal/multisig.js +11 -36
- package/dist/handlers/internal/multisig.js.map +1 -1
- package/dist/handlers/internal/sponsorship.d.ts +35 -2
- package/dist/handlers/internal/sponsorship.d.ts.map +1 -1
- package/dist/handlers/internal/sponsorship.js +53 -14
- package/dist/handlers/internal/sponsorship.js.map +1 -1
- package/dist/handlers/internal/utils.d.ts +10 -3
- package/dist/handlers/internal/utils.d.ts.map +1 -1
- package/dist/handlers/internal/utils.js +14 -6
- package/dist/handlers/internal/utils.js.map +1 -1
- package/dist/handlers/relay.d.ts +6 -2
- package/dist/handlers/relay.d.ts.map +1 -1
- package/dist/handlers/relay.js +16 -2
- package/dist/handlers/relay.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/Auth.d.ts +222 -6
- package/dist/internal/Auth.d.ts.map +1 -1
- package/dist/internal/Auth.js +625 -74
- package/dist/internal/Auth.js.map +1 -1
- package/dist/internal/Cache.d.ts.map +1 -1
- package/dist/internal/Cache.js +4 -1
- package/dist/internal/Cache.js.map +1 -1
- package/dist/internal/EdgeCache.d.ts +10 -0
- package/dist/internal/EdgeCache.d.ts.map +1 -1
- package/dist/internal/EdgeCache.js +39 -8
- package/dist/internal/EdgeCache.js.map +1 -1
- package/dist/internal/Fees.d.ts +27 -0
- package/dist/internal/Fees.d.ts.map +1 -0
- package/dist/internal/Fees.js +48 -0
- package/dist/internal/Fees.js.map +1 -0
- package/dist/internal/FundingRoutes.d.ts +183 -0
- package/dist/internal/FundingRoutes.d.ts.map +1 -0
- package/dist/internal/FundingRoutes.js +490 -0
- package/dist/internal/FundingRoutes.js.map +1 -0
- package/dist/internal/Id.d.ts +15 -0
- package/dist/internal/Id.d.ts.map +1 -0
- package/dist/internal/Id.js +22 -0
- package/dist/internal/Id.js.map +1 -0
- package/dist/internal/Log.d.ts +9 -3
- package/dist/internal/Log.d.ts.map +1 -1
- package/dist/internal/Log.js +7 -0
- package/dist/internal/Log.js.map +1 -1
- package/dist/internal/OpenApi.d.ts +10 -20
- package/dist/internal/OpenApi.d.ts.map +1 -1
- package/dist/internal/OpenApi.js +8 -58
- package/dist/internal/OpenApi.js.map +1 -1
- package/dist/internal/RateLimit.d.ts +25 -0
- package/dist/internal/RateLimit.d.ts.map +1 -1
- package/dist/internal/RateLimit.js +51 -0
- package/dist/internal/RateLimit.js.map +1 -1
- package/dist/internal/Response.d.ts +1 -1
- package/dist/internal/Response.d.ts.map +1 -1
- package/dist/internal/Schema.d.ts +8 -0
- package/dist/internal/Schema.d.ts.map +1 -1
- package/dist/internal/Schema.js +7 -0
- package/dist/internal/Schema.js.map +1 -1
- package/dist/internal/Store.d.ts +7 -1
- package/dist/internal/Store.d.ts.map +1 -1
- package/dist/internal/Store.js +16 -2
- package/dist/internal/Store.js.map +1 -1
- package/dist/internal/Viem.d.ts +84 -0
- package/dist/internal/Viem.d.ts.map +1 -1
- package/dist/internal/Webhooks.d.ts +1 -1
- package/dist/internal/Webhooks.d.ts.map +1 -1
- package/dist/internal/Webhooks.js +3 -3
- package/dist/internal/Webhooks.js.map +1 -1
- package/package.json +33 -6
- package/src/ApiKey.ts +10 -2
- package/src/ApiKeys.test.ts +155 -1
- package/src/ApiKeys.ts +203 -1
- package/src/App.test.ts +64 -75741
- package/src/App.ts +218 -420
- package/src/Client.test-d.ts +657 -15
- package/src/Scope.ts +26 -4
- package/src/Webhooks.ts +2 -2
- package/src/admin/apps/api-keys.test.ts +51 -0
- package/src/admin/apps/api-keys.ts +84 -0
- package/src/admin/apps/scopes.test.ts +11 -1
- package/src/admin/apps/scopes.ts +3 -0
- package/src/admin/apps/verified-tokens.ts +1 -1
- package/src/admin/ui/src/components/Page.tsx +2 -3
- package/src/admin/ui/src/routes/__root.tsx +2 -2
- package/src/admin/ui/src/routes/api-keys.tsx +2 -2
- package/src/admin/ui.generated.ts +13 -13
- package/src/analytics/Analytics.test.ts +527 -0
- package/src/analytics/Analytics.ts +318 -0
- package/src/analytics/tables/requestEvents.ts +523 -0
- package/src/apps/composition.test.ts +66 -0
- package/src/apps/data/App.test.ts +72 -0
- package/src/apps/data/App.ts +330 -0
- package/src/apps/data/index.ts +2 -0
- package/src/apps/{activities.test.ts → data/routes/activities.test.ts} +3 -3
- package/src/apps/{activities.ts → data/routes/activities.ts} +15 -15
- package/src/apps/{addresses.ts → data/routes/addresses.ts} +6 -6
- package/src/apps/{balances.test.ts → data/routes/balances.test.ts} +2 -2
- package/src/apps/{balances.ts → data/routes/balances.ts} +46 -12
- package/src/apps/{blocks.test.ts → data/routes/blocks.test.ts} +3 -3
- package/src/apps/{blocks.ts → data/routes/blocks.ts} +14 -14
- package/src/apps/{coingecko.test.ts → data/routes/coingecko.test.ts} +2 -2
- package/src/apps/{coingecko.ts → data/routes/coingecko.ts} +14 -14
- package/src/apps/{exchanges.test.ts → data/routes/exchanges.test.ts} +1 -1
- package/src/apps/{exchanges.ts → data/routes/exchanges.ts} +20 -20
- package/src/apps/{fee-amm.test.ts → data/routes/fee-amm.test.ts} +3 -3
- package/src/apps/{fee-amm.ts → data/routes/fee-amm.ts} +18 -18
- package/src/apps/data/routes/funding.test.ts +214 -0
- package/src/apps/data/routes/funding.ts +584 -0
- package/src/apps/{indexer.test.ts → data/routes/indexer.test.ts} +26 -5
- package/src/apps/{indexer.ts → data/routes/indexer.ts} +13 -10
- package/src/apps/{receipts.test.ts → data/routes/receipts.test.ts} +3 -3
- package/src/apps/{receipts.ts → data/routes/receipts.ts} +15 -22
- package/src/apps/{rpc.test.ts → data/routes/rpc.test.ts} +122 -7
- package/src/apps/{rpc.ts → data/routes/rpc.ts} +38 -8
- package/src/apps/{tokenlist.test.ts → data/routes/tokenlist.test.ts} +3 -3
- package/src/apps/{tokenlist.ts → data/routes/tokenlist.ts} +9 -9
- package/src/apps/{tokens.test.ts → data/routes/tokens.test.ts} +2 -2
- package/src/apps/{tokens.ts → data/routes/tokens.ts} +20 -20
- package/src/apps/{transactions.test.ts → data/routes/transactions.test.ts} +3 -3
- package/src/apps/{transactions.ts → data/routes/transactions.ts} +15 -15
- package/src/apps/{transfers.test.ts → data/routes/transfers.test.ts} +2 -2
- package/src/apps/{transfers.ts → data/routes/transfers.ts} +15 -15
- package/src/apps/{verified-tokens.test.ts → data/routes/verified-tokens.test.ts} +3 -3
- package/src/apps/{verified-tokens.ts → data/routes/verified-tokens.ts} +10 -10
- package/src/apps/{webhooks.test.ts → data/routes/webhooks.test.ts} +7 -7
- package/src/apps/{webhooks.ts → data/routes/webhooks.ts} +50 -43
- package/src/apps/docs/App.ts +65 -0
- package/src/apps/docs/index.ts +1 -0
- package/src/apps/docs/reference.ts +132 -0
- package/src/apps/index.ts +4 -0
- package/src/apps/mcp.test.ts +206 -0
- package/src/apps/mcp.ts +250 -0
- package/src/apps/metadata.ts +23 -0
- package/src/apps/platform/App.ts +169 -0
- package/src/apps/platform/Billing.test.ts +530 -0
- package/src/apps/platform/Billing.ts +682 -0
- package/src/apps/platform/index.ts +2 -0
- package/src/apps/platform/routes/api-keys.test.ts +493 -0
- package/src/apps/platform/routes/api-keys.ts +543 -0
- package/src/apps/platform/routes/billing.test.ts +1100 -0
- package/src/apps/platform/routes/billing.ts +966 -0
- package/src/apps/platform/routes/invitations.test.ts +409 -0
- package/src/apps/platform/routes/invitations.ts +587 -0
- package/src/apps/platform/routes/me.test.ts +351 -0
- package/src/apps/platform/routes/me.ts +106 -0
- package/src/apps/platform/routes/members.test.ts +195 -0
- package/src/apps/platform/routes/members.ts +313 -0
- package/src/apps/platform/routes/orgs.test.ts +313 -0
- package/src/apps/platform/routes/orgs.ts +365 -0
- package/src/apps/platform/routes/projects.test.ts +181 -0
- package/src/apps/platform/routes/projects.ts +367 -0
- package/src/apps/platform/routes/scopes.test.ts +29 -0
- package/src/apps/platform/routes/scopes.ts +85 -0
- package/src/apps/platform/routes/usage.test.ts +422 -0
- package/src/apps/platform/routes/usage.ts +527 -0
- package/src/apps/relay/App.test.ts +933 -0
- package/src/apps/relay/App.ts +236 -0
- package/src/apps/relay/Sponsorships.test.ts +375 -0
- package/src/apps/relay/Sponsorships.ts +306 -0
- package/src/apps/relay/index.ts +2 -0
- package/src/cli/Cli.test.ts +25 -2
- package/src/cli/Cli.ts +18 -3
- package/src/cli/commands/admin.test.ts +83 -0
- package/src/cli/commands/admin.ts +91 -3
- package/src/db/Db.ts +296 -0
- package/src/db/Schema.ts +241 -2
- package/src/db/tables/billingSettings.test.ts +87 -0
- package/src/db/tables/billingSettings.ts +108 -0
- package/src/db/tables/invitations.ts +198 -0
- package/src/db/tables/memberships.ts +208 -0
- package/src/db/tables/organizations.test.ts +38 -2
- package/src/db/tables/organizations.ts +117 -2
- package/src/db/tables/projects.ts +107 -0
- package/src/db/tables/requestUsage.ts +231 -0
- package/src/db/tables/sponsoredTransactions.test.ts +325 -0
- package/src/db/tables/sponsoredTransactions.ts +464 -0
- package/src/db/tables/stripeCustomers.test.ts +109 -0
- package/src/db/tables/stripeCustomers.ts +162 -0
- package/src/db/tables/users.ts +85 -0
- package/src/handlers/internal/executionError.ts +2 -0
- package/src/handlers/internal/multisig.test.ts +84 -10
- package/src/handlers/internal/multisig.ts +15 -50
- package/src/handlers/internal/sponsorship.ts +106 -20
- package/src/handlers/internal/utils.ts +19 -7
- package/src/handlers/{internal/relay.localnet.test.ts → relay.test.ts} +2 -2
- package/src/handlers/relay.ts +23 -5
- package/src/index.ts +1 -0
- package/src/internal/Auth.test.ts +491 -25
- package/src/internal/Auth.ts +839 -84
- package/src/internal/Cache.ts +5 -1
- package/src/internal/Cursor.test.ts +3 -2
- package/src/internal/EdgeCache.test.ts +27 -4
- package/src/internal/EdgeCache.ts +47 -9
- package/src/internal/Fees.test.ts +32 -0
- package/src/internal/Fees.ts +51 -0
- package/src/internal/FundingRoutes.ts +583 -0
- package/src/internal/Id.test.ts +17 -0
- package/src/internal/Id.ts +24 -0
- package/src/internal/Log.test.ts +2 -1
- package/src/internal/Log.ts +16 -3
- package/src/internal/MetricSink.ts +1 -1
- package/src/internal/OpenApi.ts +12 -60
- package/src/internal/RateLimit.test.ts +84 -0
- package/src/internal/RateLimit.ts +70 -0
- package/src/internal/Response.ts +1 -1
- package/src/internal/Schema.ts +8 -0
- package/src/internal/Store.test.ts +52 -0
- package/src/internal/Store.ts +24 -5
- package/src/internal/Tidx.local.test.ts +1 -1
- package/src/internal/VerifiedTokens.test.ts +1 -1
- package/src/internal/WebhookDestination.test.ts +1 -1
- package/src/internal/Webhooks.test.ts +7 -7
- package/src/internal/Webhooks.ts +4 -4
- package/dist/apps/activities.js.map +0 -1
- package/dist/apps/addresses.js.map +0 -1
- package/dist/apps/balances.d.ts.map +0 -1
- package/dist/apps/balances.js.map +0 -1
- package/dist/apps/blocks.d.ts.map +0 -1
- package/dist/apps/blocks.js.map +0 -1
- package/dist/apps/coingecko.d.ts.map +0 -1
- package/dist/apps/coingecko.js.map +0 -1
- package/dist/apps/exchanges.d.ts.map +0 -1
- package/dist/apps/exchanges.js.map +0 -1
- package/dist/apps/fee-amm.d.ts.map +0 -1
- package/dist/apps/fee-amm.js.map +0 -1
- package/dist/apps/indexer.d.ts.map +0 -1
- package/dist/apps/indexer.js.map +0 -1
- package/dist/apps/receipts.d.ts.map +0 -1
- package/dist/apps/receipts.js.map +0 -1
- package/dist/apps/rpc.d.ts.map +0 -1
- package/dist/apps/rpc.js.map +0 -1
- package/dist/apps/tokenlist.d.ts.map +0 -1
- package/dist/apps/tokenlist.js.map +0 -1
- package/dist/apps/tokens.d.ts.map +0 -1
- package/dist/apps/tokens.js.map +0 -1
- package/dist/apps/transactions.d.ts.map +0 -1
- package/dist/apps/transactions.js.map +0 -1
- package/dist/apps/transfers.d.ts.map +0 -1
- package/dist/apps/transfers.js.map +0 -1
- package/dist/apps/verified-tokens.d.ts.map +0 -1
- package/dist/apps/verified-tokens.js.map +0 -1
- package/dist/apps/webhooks.js.map +0 -1
- package/dist/internal/OpenApi.fonts.d.ts.map +0 -1
- package/dist/internal/OpenApi.fonts.js.map +0 -1
- package/dist/internal/OpenApi.logo.d.ts.map +0 -1
- package/dist/internal/OpenApi.logo.js.map +0 -1
- package/src/handlers/internal/multisig.localnet.test.ts +0 -146
- /package/src/{internal/OpenApi.fonts.ts → apps/docs/fonts.ts} +0 -0
- /package/src/{internal/OpenApi.logo.ts → apps/docs/logo.ts} +0 -0
package/src/internal/Cache.ts
CHANGED
|
@@ -74,7 +74,7 @@ export function response<environment extends Env>(
|
|
|
74
74
|
})
|
|
75
75
|
const etag = hono_etag()
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
const middleware: MiddlewareHandler<environment> = async (c, next) => {
|
|
78
78
|
const values = response.preservedHeaders.map((name) => [name, c.res.headers.get(name)] as const)
|
|
79
79
|
|
|
80
80
|
// Honor the standard request `Cache-Control` directives (plus the HTTP/1.0
|
|
@@ -155,6 +155,10 @@ export function response<environment extends Env>(
|
|
|
155
155
|
if (result instanceof Response) return res
|
|
156
156
|
return undefined
|
|
157
157
|
}
|
|
158
|
+
|
|
159
|
+
// `markCacheable` lets the edge layer pay its store lookup only on routes
|
|
160
|
+
// that mount this middleware; everything else skips the read.
|
|
161
|
+
return EdgeCache.markCacheable(middleware)
|
|
158
162
|
}
|
|
159
163
|
|
|
160
164
|
export declare namespace response {
|
|
@@ -90,11 +90,12 @@ describe('Cursor', () => {
|
|
|
90
90
|
})
|
|
91
91
|
|
|
92
92
|
test('falls back to an OR expansion for a mixed-direction keyset', () => {
|
|
93
|
+
const holder = `'0x${'ab'.repeat(20)}'`
|
|
93
94
|
expect(
|
|
94
95
|
Cursor.keyset([
|
|
95
96
|
{ literal: '1000', name: 'balance', order: 'desc' },
|
|
96
|
-
{ literal:
|
|
97
|
+
{ literal: holder, name: 'holder', order: 'asc' },
|
|
97
98
|
]),
|
|
98
|
-
).toBe(
|
|
99
|
+
).toBe(`(balance <= 1000 AND ((balance < 1000) OR (balance = 1000 AND holder > ${holder})))`)
|
|
99
100
|
})
|
|
100
101
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Hono } from 'hono'
|
|
2
|
+
import { createMiddleware } from 'hono/factory'
|
|
2
3
|
import * as EdgeCache from './EdgeCache.js'
|
|
3
4
|
import type * as Store from './Store.js'
|
|
4
5
|
|
|
@@ -128,6 +129,18 @@ describe('middleware', () => {
|
|
|
128
129
|
expect(store.size).toMatchInlineSnapshot(`0`)
|
|
129
130
|
})
|
|
130
131
|
|
|
132
|
+
test('skips the store lookup for routes that did not opt in', async () => {
|
|
133
|
+
const { app, store } = createApp()
|
|
134
|
+
|
|
135
|
+
await app.request('/uncached')
|
|
136
|
+
await app.request('/missing-route')
|
|
137
|
+
expect(store.gets).toMatchInlineSnapshot(`0`)
|
|
138
|
+
|
|
139
|
+
// Marked routes still pay (and use) the lookup.
|
|
140
|
+
await app.request('/cached')
|
|
141
|
+
expect(store.gets).toMatchInlineSnapshot(`1`)
|
|
142
|
+
})
|
|
143
|
+
|
|
131
144
|
test('answers conditional requests from a cached ETag with 304', async () => {
|
|
132
145
|
const { app } = createApp()
|
|
133
146
|
|
|
@@ -172,13 +185,18 @@ type Environment = { Variables: EdgeCache.Variables }
|
|
|
172
185
|
// In-memory `Store.Store` so the edge cache and origin cache share one shape.
|
|
173
186
|
function memoryStore() {
|
|
174
187
|
const map = new Map<string, string>()
|
|
188
|
+
let gets = 0
|
|
175
189
|
return {
|
|
176
190
|
async delete(key: string) {
|
|
177
191
|
map.delete(key)
|
|
178
192
|
},
|
|
179
193
|
async get(key: string) {
|
|
194
|
+
gets++
|
|
180
195
|
return map.get(key) ?? null
|
|
181
196
|
},
|
|
197
|
+
get gets() {
|
|
198
|
+
return gets
|
|
199
|
+
},
|
|
182
200
|
async list() {
|
|
183
201
|
return { keys: [...map.keys()].map((name) => ({ name })) }
|
|
184
202
|
},
|
|
@@ -189,7 +207,7 @@ function memoryStore() {
|
|
|
189
207
|
return map.size
|
|
190
208
|
},
|
|
191
209
|
type: 'state',
|
|
192
|
-
} satisfies Store.Store & { readonly size: number }
|
|
210
|
+
} satisfies Store.Store & { readonly gets: number; readonly size: number }
|
|
193
211
|
}
|
|
194
212
|
|
|
195
213
|
function createApp(options: { store?: Store.Store | undefined } = {}) {
|
|
@@ -203,7 +221,12 @@ function createApp(options: { store?: Store.Store | undefined } = {}) {
|
|
|
203
221
|
downstream++
|
|
204
222
|
await next()
|
|
205
223
|
})
|
|
206
|
-
|
|
224
|
+
// Routes publishing a policy mount a marked middleware, as `Cache.response`
|
|
225
|
+
// routes do; unmarked routes must skip the lookup entirely.
|
|
226
|
+
const cacheable = EdgeCache.markCacheable(
|
|
227
|
+
createMiddleware<Environment>(async (_c, next) => next()),
|
|
228
|
+
)
|
|
229
|
+
app.get('/cached', cacheable, (c) => {
|
|
207
230
|
c.set('edgeCache', { maxAge: 30, staleWhileRevalidate: 300 })
|
|
208
231
|
c.header('Age', '123')
|
|
209
232
|
c.header('CF-Cache-Status', 'HIT')
|
|
@@ -212,11 +235,11 @@ function createApp(options: { store?: Store.Store | undefined } = {}) {
|
|
|
212
235
|
c.header('RateLimit-Remaining', '9')
|
|
213
236
|
return c.json({ ok: true })
|
|
214
237
|
})
|
|
215
|
-
app.get('/error', (c) => {
|
|
238
|
+
app.get('/error', cacheable, (c) => {
|
|
216
239
|
c.set('edgeCache', { maxAge: 30, staleWhileRevalidate: 300 })
|
|
217
240
|
return c.json({ ok: false }, 500)
|
|
218
241
|
})
|
|
219
|
-
app.get('/binary', (c) => {
|
|
242
|
+
app.get('/binary', cacheable, (c) => {
|
|
220
243
|
c.set('edgeCache', { maxAge: 30, staleWhileRevalidate: 300 })
|
|
221
244
|
// Bytes that are not valid UTF-8 (PNG signature) — corrupted if stored via
|
|
222
245
|
// `.text()` instead of base64.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Env, MiddlewareHandler } from 'hono'
|
|
1
|
+
import type { Context, Env, MiddlewareHandler } from 'hono'
|
|
2
|
+
import { matchedRoutes } from 'hono/route'
|
|
2
3
|
import { Base64 } from 'ox'
|
|
3
4
|
|
|
4
5
|
import type * as Store from './Store.js'
|
|
@@ -53,6 +54,10 @@ const volatileHeaders = [
|
|
|
53
54
|
* is that cache hits bypass origin metering: they are not counted against
|
|
54
55
|
* rate-limit quotas.
|
|
55
56
|
*
|
|
57
|
+
* Lookups are equally scoped: only requests whose matched route carries the
|
|
58
|
+
* {@link markCacheable} marker (applied by `Cache.response`) pay the store
|
|
59
|
+
* read, so GETs to non-cacheable routes skip the round trip entirely.
|
|
60
|
+
*
|
|
56
61
|
* The cache is a plain `Store.Store` — the same store the origin read cache uses
|
|
57
62
|
* — holding the response serialized to a string under a URL key. It is a no-op
|
|
58
63
|
* when no store is supplied.
|
|
@@ -68,8 +73,14 @@ export function middleware<environment extends Env>(
|
|
|
68
73
|
): MiddlewareHandler<environment> {
|
|
69
74
|
return async (c, next) => {
|
|
70
75
|
const { store } = options
|
|
76
|
+
// Pay the store lookup only when a matched handler is marked cacheable
|
|
77
|
+
// (mounted `Cache.response`); other GETs (authed platform routes, docs,
|
|
78
|
+
// 404s) can never hit, so the read would be a wasted round trip.
|
|
71
79
|
const eligible =
|
|
72
|
-
store !== undefined &&
|
|
80
|
+
store !== undefined &&
|
|
81
|
+
c.req.method === 'GET' &&
|
|
82
|
+
!c.req.raw.headers.has('range') &&
|
|
83
|
+
isCacheableRoute(c)
|
|
73
84
|
const key = eligible ? cacheKey(c.req.url) : undefined
|
|
74
85
|
|
|
75
86
|
// Honor the standard request `Cache-Control` directives so a caller can
|
|
@@ -104,16 +115,41 @@ export function middleware<environment extends Env>(
|
|
|
104
115
|
if (c.res.headers.get('content-type')?.includes('text/event-stream')) return
|
|
105
116
|
|
|
106
117
|
// Store a public, sanitized copy; the client still receives the original
|
|
107
|
-
// (private, metered) response for this miss.
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
// (private, metered) response for this miss. Clone synchronously — the
|
|
119
|
+
// original body locks once it streams to the client — then serialize and
|
|
120
|
+
// write behind `waitUntil` so the miss response is not held open on the
|
|
121
|
+
// body read.
|
|
122
|
+
const copy = c.res.clone()
|
|
123
|
+
const persist = serialize(copy, policy).then((value) =>
|
|
124
|
+
store.put(key, value, { ttl: policy.maxAge * 1_000 }),
|
|
125
|
+
)
|
|
110
126
|
const waitUntil = getWaitUntil(c)
|
|
111
|
-
if (waitUntil) waitUntil(
|
|
112
|
-
else await
|
|
127
|
+
if (waitUntil) waitUntil(persist)
|
|
128
|
+
else await persist.catch(() => {})
|
|
113
129
|
return
|
|
114
130
|
}
|
|
115
131
|
}
|
|
116
132
|
|
|
133
|
+
// Marks handlers whose route publishes an edge-cache policy; the middleware
|
|
134
|
+
// pays the store lookup only when a matched handler carries it.
|
|
135
|
+
const cacheableSymbol = Symbol('tempoApi.edgeCacheable')
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Marks a route handler/middleware as publishing an edge-cache policy, so
|
|
139
|
+
* {@link middleware} looks its route up in the edge cache. `Cache.response`
|
|
140
|
+
* applies it; routes composed any other way never enter the shared cache.
|
|
141
|
+
*/
|
|
142
|
+
export function markCacheable<const handler extends (...args: never[]) => unknown>(
|
|
143
|
+
handler: handler,
|
|
144
|
+
): handler {
|
|
145
|
+
return Object.assign(handler, { [cacheableSymbol]: true })
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// True when any handler matched for this request is marked cacheable.
|
|
149
|
+
function isCacheableRoute(c: Context): boolean {
|
|
150
|
+
return matchedRoutes(c).some((route) => cacheableSymbol in route.handler)
|
|
151
|
+
}
|
|
152
|
+
|
|
117
153
|
export declare namespace middleware {
|
|
118
154
|
/** Options for the edge-cache middleware. */
|
|
119
155
|
type Options = {
|
|
@@ -134,6 +170,8 @@ type Stored = {
|
|
|
134
170
|
status: number
|
|
135
171
|
}
|
|
136
172
|
|
|
173
|
+
// Consumes `response` (callers pass a dedicated clone; the client streams the
|
|
174
|
+
// original).
|
|
137
175
|
async function serialize(response: Response, policy: Policy): Promise<string> {
|
|
138
176
|
const headers = new Headers(response.headers)
|
|
139
177
|
for (const name of volatileHeaders) headers.delete(name)
|
|
@@ -145,8 +183,8 @@ async function serialize(response: Response, policy: Policy): Promise<string> {
|
|
|
145
183
|
const textual = isTextual(headers.get('content-type'))
|
|
146
184
|
const stored: Stored = {
|
|
147
185
|
body: textual
|
|
148
|
-
? await response.
|
|
149
|
-
: Base64.fromBytes(new Uint8Array(await response.
|
|
186
|
+
? await response.text()
|
|
187
|
+
: Base64.fromBytes(new Uint8Array(await response.arrayBuffer())),
|
|
150
188
|
...(textual ? {} : { encoding: 'base64' as const }),
|
|
151
189
|
headers: [...headers],
|
|
152
190
|
status: response.status,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as Fees from './Fees.js'
|
|
2
|
+
|
|
3
|
+
describe('fromGas', () => {
|
|
4
|
+
test('behavior: scales attodollar gas math to token units with ceiling division', () => {
|
|
5
|
+
// 100k gas × 1e6 atto = 1e11 atto rounds up to one token unit.
|
|
6
|
+
expect(Fees.fromGas(100_000n, 1_000_000n)).toBe(1n)
|
|
7
|
+
// 1M gas × 5e11 atto = 5e17 atto = $0.50 exactly.
|
|
8
|
+
expect(Fees.fromGas(1_000_000n, 500_000_000_000n)).toBe(500_000n)
|
|
9
|
+
// Any remainder rounds up, mirroring `calc_gas_balance_spending`.
|
|
10
|
+
expect(Fees.fromGas(1n, 1_000_000_000_001n)).toBe(2n)
|
|
11
|
+
expect(Fees.fromGas(0n, 0n)).toBe(0n)
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
describe('maxOf', () => {
|
|
16
|
+
test('behavior: computes the signed cap from bigint or hex quantity fields', () => {
|
|
17
|
+
expect(Fees.maxOf({ gas: 1_000_000n, maxFeePerGas: 500_000_000_000n })).toBe(500_000n)
|
|
18
|
+
// Fills carry hex quantities: 0xf4240 = 1M gas, 0x746a528800 = 5e11 atto.
|
|
19
|
+
expect(Fees.maxOf({ gas: '0xf4240', maxFeePerGas: '0x746a528800' })).toBe(500_000n)
|
|
20
|
+
// Zero fields are computable (a zero cap), not absent.
|
|
21
|
+
expect(Fees.maxOf({ gas: 0n, maxFeePerGas: 0n })).toBe(0n)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('behavior: yields undefined when either fee field is missing or unparseable', () => {
|
|
25
|
+
expect(Fees.maxOf({})).toBeUndefined()
|
|
26
|
+
expect(Fees.maxOf({ gas: 21_000n })).toBeUndefined()
|
|
27
|
+
expect(Fees.maxOf({ maxFeePerGas: 1_000_000n })).toBeUndefined()
|
|
28
|
+
// Decimal strings are not hex quantities; callers fail closed.
|
|
29
|
+
expect(Fees.maxOf({ gas: '21000', maxFeePerGas: 1_000_000n })).toBeUndefined()
|
|
30
|
+
expect(Fees.maxOf({ gas: null, maxFeePerGas: 1_000_000n })).toBeUndefined()
|
|
31
|
+
})
|
|
32
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Hex } from 'ox'
|
|
2
|
+
|
|
3
|
+
// Tempo gas prices (`maxFeePerGas`, `effectiveGasPrice`, block base fee) are
|
|
4
|
+
// denominated in attodollars (10^-18 USD) per gas, while fee-token balances
|
|
5
|
+
// use 6 decimals (microdollars, 10^-6 USD). The charged fee is
|
|
6
|
+
// `ceil(gas × gasPrice / 10^12)`, mirroring `calc_gas_balance_spending` in
|
|
7
|
+
// tempoxyz/tempo.
|
|
8
|
+
|
|
9
|
+
/** Attodollar exponent gas prices use (10^-18 USD per gas), fixed by the fee spec. */
|
|
10
|
+
const attoDecimals = 18
|
|
11
|
+
|
|
12
|
+
/** Fee-token decimals: TIP-20 fixes 6 (1 token unit = 1 microdollar). */
|
|
13
|
+
export const tokenDecimals = 6
|
|
14
|
+
|
|
15
|
+
/** Scaling between attodollar gas math and fee-token units, derived from the exponents. */
|
|
16
|
+
export const scalingFactor = 10n ** BigInt(attoDecimals - tokenDecimals)
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Fee in fee-token base units for a gas amount priced in attodollars per gas
|
|
20
|
+
* (ceiling division). Works for actual fees (`gasUsed × effectiveGasPrice`)
|
|
21
|
+
* and signed caps (`gas × maxFeePerGas`) alike.
|
|
22
|
+
*
|
|
23
|
+
* @param gas - Gas amount.
|
|
24
|
+
* @param gasPrice - Price in attodollars per gas.
|
|
25
|
+
* @returns The fee in fee-token base units.
|
|
26
|
+
*/
|
|
27
|
+
export function fromGas(gas: bigint, gasPrice: bigint): bigint {
|
|
28
|
+
return (gas * gasPrice + scalingFactor - 1n) / scalingFactor
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Signed fee cap of a candidate transaction in fee-token base units:
|
|
33
|
+
* `gas × maxFeePerGas` (attodollars) scaled through {@link fromGas}. Undefined
|
|
34
|
+
* when either field is missing or unparseable, so callers can fail closed.
|
|
35
|
+
*
|
|
36
|
+
* @param request - Transaction-shaped fee fields.
|
|
37
|
+
* @returns The cap in base units, or undefined.
|
|
38
|
+
*/
|
|
39
|
+
export function maxOf(request: { gas?: unknown; maxFeePerGas?: unknown }): bigint | undefined {
|
|
40
|
+
const gas = toBigInt(request.gas)
|
|
41
|
+
const maxFeePerGas = toBigInt(request.maxFeePerGas)
|
|
42
|
+
if (gas === undefined || maxFeePerGas === undefined) return undefined
|
|
43
|
+
return fromGas(gas, maxFeePerGas)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Fee fields arrive as bigints (raw envelopes) or hex quantities (fills). */
|
|
47
|
+
function toBigInt(value: unknown): bigint | undefined {
|
|
48
|
+
if (typeof value === 'bigint') return value
|
|
49
|
+
if (typeof value === 'string' && Hex.validate(value)) return Hex.toBigInt(value)
|
|
50
|
+
return undefined
|
|
51
|
+
}
|