@helium/blockchain-api 0.1.2 → 0.1.3
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 +24 -2
- package/package.json +31 -31
- package/types/README.md +24 -2
- package/types/generated/index.d.mts +2481 -0
- package/types/generated/index.d.ts +2481 -0
- package/types/generated/index.js +723 -0
- package/types/generated/index.mjs +614 -0
- package/types/index.ts +11 -8
- package/src/server/api/errors.ts +0 -152
- package/src/server/api/index.ts +0 -40
- package/src/server/api/procedures.ts +0 -144
- package/src/server/api/routers/fiat/router.ts +0 -709
- package/src/server/api/routers/fiat/schemas.ts +0 -169
- package/src/server/api/routers/health/router.ts +0 -41
- package/src/server/api/routers/hotspots/procedures/claimRewards.ts +0 -258
- package/src/server/api/routers/hotspots/procedures/createSplit.ts +0 -253
- package/src/server/api/routers/hotspots/procedures/deleteSplit.ts +0 -156
- package/src/server/api/routers/hotspots/procedures/getHotspots.ts +0 -31
- package/src/server/api/routers/hotspots/procedures/getPendingRewards.ts +0 -44
- package/src/server/api/routers/hotspots/procedures/getSplit.ts +0 -88
- package/src/server/api/routers/hotspots/procedures/transferHotspot.ts +0 -204
- package/src/server/api/routers/hotspots/procedures/updateRewardsDestination.ts +0 -201
- package/src/server/api/routers/hotspots/router.ts +0 -30
- package/src/server/api/routers/hotspots/schemas.ts +0 -182
- package/src/server/api/routers/swap/procedures/getInstructions.ts +0 -152
- package/src/server/api/routers/swap/procedures/getQuote.ts +0 -53
- package/src/server/api/routers/swap/procedures/getTokens.ts +0 -88
- package/src/server/api/routers/swap/router.ts +0 -15
- package/src/server/api/routers/swap/schemas.ts +0 -96
- package/src/server/api/routers/tokens/procedures/createHntAccount.ts +0 -87
- package/src/server/api/routers/tokens/procedures/getBalances.ts +0 -27
- package/src/server/api/routers/tokens/procedures/transfer.ts +0 -159
- package/src/server/api/routers/tokens/router.ts +0 -15
- package/src/server/api/routers/tokens/schemas.ts +0 -80
- package/src/server/api/routers/transactions/procedures/get.ts +0 -46
- package/src/server/api/routers/transactions/procedures/getByPayer.ts +0 -111
- package/src/server/api/routers/transactions/procedures/getByPayerAndTag.ts +0 -119
- package/src/server/api/routers/transactions/procedures/resubmit.ts +0 -68
- package/src/server/api/routers/transactions/procedures/submit.ts +0 -216
- package/src/server/api/routers/transactions/router.ts +0 -21
- package/src/server/api/routers/transactions/schemas.ts +0 -119
- package/src/server/api/routers/webhooks/router.ts +0 -75
- package/src/server/api/routers/welcomePacks/procedures/claim.ts +0 -157
- package/src/server/api/routers/welcomePacks/procedures/create.ts +0 -247
- package/src/server/api/routers/welcomePacks/procedures/deletePack.ts +0 -118
- package/src/server/api/routers/welcomePacks/procedures/get.ts +0 -36
- package/src/server/api/routers/welcomePacks/procedures/getByAddress.ts +0 -26
- package/src/server/api/routers/welcomePacks/procedures/invite.ts +0 -44
- package/src/server/api/routers/welcomePacks/procedures/list.ts +0 -27
- package/src/server/api/routers/welcomePacks/router.ts +0 -27
- package/src/server/api/routers/welcomePacks/schemas.ts +0 -135
- package/src/server/api/schemas.ts +0 -281
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { publicProcedure } from "../../../procedures";
|
|
2
|
-
import {
|
|
3
|
-
TransferHotspotInputSchema,
|
|
4
|
-
TransferHotspotOutputSchema,
|
|
5
|
-
} from "../schemas";
|
|
6
|
-
import { ORPCError } from "@orpc/server";
|
|
7
|
-
import { Connection, PublicKey } from "@solana/web3.js";
|
|
8
|
-
import { env } from "@/lib/env";
|
|
9
|
-
import {
|
|
10
|
-
generateTransactionTag,
|
|
11
|
-
TRANSACTION_TYPES,
|
|
12
|
-
} from "@/lib/utils/transaction-tags";
|
|
13
|
-
import {
|
|
14
|
-
populateMissingDraftInfo,
|
|
15
|
-
toVersionedTx,
|
|
16
|
-
withPriorityFees,
|
|
17
|
-
proofArgsAndAccounts,
|
|
18
|
-
type Asset,
|
|
19
|
-
} from "@helium/spl-utils";
|
|
20
|
-
import {
|
|
21
|
-
PROGRAM_ID as BUBBLEGUM_PROGRAM_ID,
|
|
22
|
-
createTransferInstruction,
|
|
23
|
-
} from "@metaplex-foundation/mpl-bubblegum";
|
|
24
|
-
import {
|
|
25
|
-
SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
|
|
26
|
-
SPL_NOOP_PROGRAM_ID,
|
|
27
|
-
} from "@solana/spl-account-compression";
|
|
28
|
-
import { entityCreatorKey } from "@helium/helium-entity-manager-sdk";
|
|
29
|
-
import { daoKey } from "@helium/helium-sub-daos-sdk";
|
|
30
|
-
import { HNT_MINT } from "@helium/spl-utils";
|
|
31
|
-
import { getAssetIdFromPubkey } from "@/lib/utils/hotspot-helpers";
|
|
32
|
-
|
|
33
|
-
const DAO_KEY = daoKey(HNT_MINT)[0];
|
|
34
|
-
|
|
35
|
-
async function getBubblegumAuthorityPDA(
|
|
36
|
-
merkleRollPubKey: PublicKey,
|
|
37
|
-
): Promise<PublicKey> {
|
|
38
|
-
const [bubblegumAuthorityPDAKey] = await PublicKey.findProgramAddress(
|
|
39
|
-
[merkleRollPubKey.toBuffer()],
|
|
40
|
-
BUBBLEGUM_PROGRAM_ID,
|
|
41
|
-
);
|
|
42
|
-
return bubblegumAuthorityPDAKey;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function validateHeliumHotspot(asset: Asset): boolean {
|
|
46
|
-
const heliumEntityCreator = entityCreatorKey(DAO_KEY)[0].toBase58();
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
asset.creators?.some((creator) => {
|
|
50
|
-
const address =
|
|
51
|
-
typeof creator.address === "string"
|
|
52
|
-
? creator.address
|
|
53
|
-
: creator.address.toBase58();
|
|
54
|
-
return address === heliumEntityCreator && creator.verified;
|
|
55
|
-
}) || false
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Create a transaction to transfer a hotspot to a new owner.
|
|
61
|
-
*/
|
|
62
|
-
export const transferHotspot = publicProcedure
|
|
63
|
-
.route({
|
|
64
|
-
method: "POST",
|
|
65
|
-
path: "/hotspots/wallet/{walletAddress}/{hotspotPubkey}/transfer",
|
|
66
|
-
})
|
|
67
|
-
.input(TransferHotspotInputSchema)
|
|
68
|
-
.output(TransferHotspotOutputSchema)
|
|
69
|
-
.errors({
|
|
70
|
-
NOT_FOUND: { message: "Hotspot not found" },
|
|
71
|
-
BAD_REQUEST: { message: "Invalid request" },
|
|
72
|
-
FORBIDDEN: { message: "Wallet is not the owner of this hotspot" },
|
|
73
|
-
INVALID_HOTSPOT: { message: "Asset is not a valid Helium hotspot" },
|
|
74
|
-
})
|
|
75
|
-
.handler(async ({ input, errors }) => {
|
|
76
|
-
const { walletAddress, hotspotPubkey, recipient } = input;
|
|
77
|
-
|
|
78
|
-
// Resolve hotspot pubkey to asset ID
|
|
79
|
-
const assetId = await getAssetIdFromPubkey(hotspotPubkey);
|
|
80
|
-
if (!assetId) {
|
|
81
|
-
throw errors.NOT_FOUND({ message: "Hotspot not found" });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Validate public keys
|
|
85
|
-
let payerPubkey: PublicKey;
|
|
86
|
-
let recipientPubkey: PublicKey;
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
payerPubkey = new PublicKey(walletAddress);
|
|
90
|
-
recipientPubkey = new PublicKey(recipient);
|
|
91
|
-
} catch {
|
|
92
|
-
throw errors.BAD_REQUEST({ message: "Invalid public key format" });
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const connection = new Connection(env.SOLANA_RPC_URL);
|
|
96
|
-
const assetEndpoint = env.ASSET_ENDPOINT || connection.rpcEndpoint;
|
|
97
|
-
const assetPubkey = new PublicKey(assetId);
|
|
98
|
-
|
|
99
|
-
const { asset, args, accounts, remainingAccounts } =
|
|
100
|
-
await proofArgsAndAccounts({
|
|
101
|
-
connection,
|
|
102
|
-
assetId: assetPubkey,
|
|
103
|
-
assetEndpoint,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
if (!asset) {
|
|
107
|
-
throw errors.NOT_FOUND({ message: "Asset not found" });
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Validate asset is a Helium hotspot
|
|
111
|
-
if (!validateHeliumHotspot(asset)) {
|
|
112
|
-
throw errors.INVALID_HOTSPOT({
|
|
113
|
-
message: "Asset is not a valid Helium hotspot",
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Validate ownership
|
|
118
|
-
const ownerAddress =
|
|
119
|
-
typeof asset.ownership.owner === "string"
|
|
120
|
-
? asset.ownership.owner
|
|
121
|
-
: asset.ownership.owner.toBase58();
|
|
122
|
-
|
|
123
|
-
if (ownerAddress !== walletAddress) {
|
|
124
|
-
throw errors.FORBIDDEN({
|
|
125
|
-
message: "Wallet is not the owner of this hotspot",
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const leafOwner =
|
|
130
|
-
typeof asset.ownership.owner === "string"
|
|
131
|
-
? new PublicKey(asset.ownership.owner)
|
|
132
|
-
: asset.ownership.owner;
|
|
133
|
-
|
|
134
|
-
const leafDelegate = asset.ownership.delegate
|
|
135
|
-
? typeof asset.ownership.delegate === "string"
|
|
136
|
-
? new PublicKey(asset.ownership.delegate)
|
|
137
|
-
: asset.ownership.delegate
|
|
138
|
-
: leafOwner;
|
|
139
|
-
|
|
140
|
-
const merkleTree = accounts.merkleTree;
|
|
141
|
-
const treeAuthority = await getBubblegumAuthorityPDA(merkleTree);
|
|
142
|
-
|
|
143
|
-
const transferInstruction = createTransferInstruction(
|
|
144
|
-
{
|
|
145
|
-
treeAuthority,
|
|
146
|
-
leafOwner,
|
|
147
|
-
leafDelegate,
|
|
148
|
-
newLeafOwner: recipientPubkey,
|
|
149
|
-
merkleTree,
|
|
150
|
-
logWrapper: SPL_NOOP_PROGRAM_ID,
|
|
151
|
-
compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
|
|
152
|
-
anchorRemainingAccounts: remainingAccounts,
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
...args,
|
|
156
|
-
nonce: args.index,
|
|
157
|
-
},
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
const instructionsWithFees = await withPriorityFees({
|
|
161
|
-
connection,
|
|
162
|
-
instructions: [transferInstruction],
|
|
163
|
-
feePayer: payerPubkey,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const draft = await populateMissingDraftInfo(connection, {
|
|
167
|
-
instructions: instructionsWithFees,
|
|
168
|
-
feePayer: payerPubkey,
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const versionedTx = toVersionedTx(draft);
|
|
172
|
-
const serializedTransaction = Buffer.from(versionedTx.serialize()).toString(
|
|
173
|
-
"base64",
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
const tag = generateTransactionTag({
|
|
177
|
-
type: TRANSACTION_TYPES.HOTSPOT_TRANSFER,
|
|
178
|
-
walletAddress,
|
|
179
|
-
assetId,
|
|
180
|
-
recipient,
|
|
181
|
-
timestamp: Date.now(),
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
const hotspotName = asset.content?.metadata?.name || "Hotspot";
|
|
185
|
-
|
|
186
|
-
return {
|
|
187
|
-
transactionData: {
|
|
188
|
-
transactions: [
|
|
189
|
-
{
|
|
190
|
-
serializedTransaction,
|
|
191
|
-
metadata: {
|
|
192
|
-
type: TRANSACTION_TYPES.HOTSPOT_TRANSFER,
|
|
193
|
-
description: `Transfer ${hotspotName} to ${recipient.slice(
|
|
194
|
-
0,
|
|
195
|
-
4,
|
|
196
|
-
)}...${recipient.slice(-4)}`,
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
parallel: false,
|
|
201
|
-
tag,
|
|
202
|
-
},
|
|
203
|
-
};
|
|
204
|
-
});
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { publicProcedure } from "../../../procedures";
|
|
2
|
-
import {
|
|
3
|
-
UpdateRewardsDestinationInputSchema,
|
|
4
|
-
UpdateRewardsDestinationOutputSchema,
|
|
5
|
-
} from "../schemas";
|
|
6
|
-
import { ORPCError } from "@orpc/server";
|
|
7
|
-
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
8
|
-
import {
|
|
9
|
-
generateTransactionTag,
|
|
10
|
-
TRANSACTION_TYPES,
|
|
11
|
-
} from "@/lib/utils/transaction-tags";
|
|
12
|
-
import {
|
|
13
|
-
populateMissingDraftInfo,
|
|
14
|
-
toVersionedTx,
|
|
15
|
-
withPriorityFees,
|
|
16
|
-
proofArgsAndAccounts,
|
|
17
|
-
} from "@helium/spl-utils";
|
|
18
|
-
import {
|
|
19
|
-
init as initLazy,
|
|
20
|
-
initializeCompressionRecipient,
|
|
21
|
-
recipientKey,
|
|
22
|
-
} from "@helium/lazy-distributor-sdk";
|
|
23
|
-
import { createSolanaConnection } from "@/lib/solana";
|
|
24
|
-
import { env } from "@/lib/env";
|
|
25
|
-
import { getAssetIdFromPubkey } from "@/lib/utils/hotspot-helpers";
|
|
26
|
-
|
|
27
|
-
async function exists(
|
|
28
|
-
connection: { getAccountInfo: (account: PublicKey) => Promise<unknown> },
|
|
29
|
-
account: PublicKey,
|
|
30
|
-
): Promise<boolean> {
|
|
31
|
-
return Boolean(await connection.getAccountInfo(account));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Update the rewards destination for a hotspot across one or more lazy distributors.
|
|
36
|
-
*/
|
|
37
|
-
export const updateRewardsDestination = publicProcedure
|
|
38
|
-
.route({
|
|
39
|
-
method: "POST",
|
|
40
|
-
path: "/hotspots/wallet/{walletAddress}/{hotspotPubkey}/update-rewards-destination",
|
|
41
|
-
})
|
|
42
|
-
.input(UpdateRewardsDestinationInputSchema)
|
|
43
|
-
.output(UpdateRewardsDestinationOutputSchema)
|
|
44
|
-
.errors({
|
|
45
|
-
NOT_FOUND: { message: "Hotspot not found" },
|
|
46
|
-
BAD_REQUEST: { message: "Invalid request" },
|
|
47
|
-
})
|
|
48
|
-
.handler(async ({ input, errors }) => {
|
|
49
|
-
const { walletAddress, hotspotPubkey, lazyDistributors, destination } =
|
|
50
|
-
input;
|
|
51
|
-
|
|
52
|
-
// Resolve hotspot pubkey to asset ID
|
|
53
|
-
const assetId = await getAssetIdFromPubkey(hotspotPubkey);
|
|
54
|
-
if (!assetId) {
|
|
55
|
-
throw errors.NOT_FOUND({ message: "Hotspot not found" });
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Validate public keys
|
|
59
|
-
let assetPubkey: PublicKey;
|
|
60
|
-
let destinationPubkey: PublicKey;
|
|
61
|
-
const lazyDistributorPubkeys: PublicKey[] = [];
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
assetPubkey = new PublicKey(assetId);
|
|
65
|
-
destinationPubkey = new PublicKey(destination);
|
|
66
|
-
|
|
67
|
-
for (const ld of lazyDistributors) {
|
|
68
|
-
lazyDistributorPubkeys.push(new PublicKey(ld));
|
|
69
|
-
}
|
|
70
|
-
} catch {
|
|
71
|
-
throw errors.BAD_REQUEST({ message: "Invalid public key format" });
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Create connection and provider
|
|
75
|
-
const { connection, provider, wallet } =
|
|
76
|
-
createSolanaConnection(walletAddress);
|
|
77
|
-
|
|
78
|
-
// Check if destination exists
|
|
79
|
-
const destinationExists = await exists(connection, destinationPubkey);
|
|
80
|
-
|
|
81
|
-
const program = await initLazy(provider);
|
|
82
|
-
|
|
83
|
-
// Get proof args and accounts for the asset
|
|
84
|
-
const assetEndpoint =
|
|
85
|
-
env.ASSET_ENDPOINT || program.provider.connection.rpcEndpoint;
|
|
86
|
-
|
|
87
|
-
const {
|
|
88
|
-
asset: {
|
|
89
|
-
ownership: { owner },
|
|
90
|
-
},
|
|
91
|
-
args,
|
|
92
|
-
accounts,
|
|
93
|
-
remainingAccounts,
|
|
94
|
-
} = await proofArgsAndAccounts({
|
|
95
|
-
connection: program.provider.connection,
|
|
96
|
-
assetId: assetPubkey,
|
|
97
|
-
assetEndpoint,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// Build instructions for each lazy distributor
|
|
101
|
-
const instructions: TransactionInstruction[] = (
|
|
102
|
-
await Promise.all(
|
|
103
|
-
lazyDistributorPubkeys.map(async (lazy) => {
|
|
104
|
-
const [recipientPk] = recipientKey(lazy, assetPubkey);
|
|
105
|
-
const recipientExists = await exists(connection, recipientPk);
|
|
106
|
-
|
|
107
|
-
const ixs: TransactionInstruction[] = [];
|
|
108
|
-
|
|
109
|
-
// Initialize recipient if it doesn't exist
|
|
110
|
-
if (!recipientExists) {
|
|
111
|
-
ixs.push(
|
|
112
|
-
await (
|
|
113
|
-
await initializeCompressionRecipient({
|
|
114
|
-
program,
|
|
115
|
-
assetId: assetPubkey,
|
|
116
|
-
lazyDistributor: lazy,
|
|
117
|
-
payer: wallet.publicKey,
|
|
118
|
-
})
|
|
119
|
-
).instruction(),
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Create update compression destination instruction
|
|
124
|
-
ixs.push(
|
|
125
|
-
await program.methods
|
|
126
|
-
.updateCompressionDestinationV0({
|
|
127
|
-
...args,
|
|
128
|
-
})
|
|
129
|
-
.accountsPartial({
|
|
130
|
-
...accounts,
|
|
131
|
-
owner,
|
|
132
|
-
recipient: recipientKey(lazy, assetPubkey)[0],
|
|
133
|
-
destination:
|
|
134
|
-
destination === PublicKey.default.toBase58()
|
|
135
|
-
? PublicKey.default
|
|
136
|
-
: destinationPubkey,
|
|
137
|
-
})
|
|
138
|
-
.remainingAccounts(remainingAccounts)
|
|
139
|
-
.instruction(),
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
return ixs;
|
|
143
|
-
}),
|
|
144
|
-
)
|
|
145
|
-
).flat();
|
|
146
|
-
|
|
147
|
-
// Add priority fees
|
|
148
|
-
const instructionsWithFees = await withPriorityFees({
|
|
149
|
-
connection,
|
|
150
|
-
instructions,
|
|
151
|
-
feePayer: wallet.publicKey,
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// Populate missing transaction info
|
|
155
|
-
const draft = await populateMissingDraftInfo(connection, {
|
|
156
|
-
instructions: instructionsWithFees,
|
|
157
|
-
feePayer: wallet.publicKey,
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// Convert to versioned transaction
|
|
161
|
-
const versionedTx = toVersionedTx(draft);
|
|
162
|
-
const serializedTransaction = Buffer.from(versionedTx.serialize()).toString(
|
|
163
|
-
"base64",
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
// Generate transaction tag for deduplication
|
|
167
|
-
const tag = generateTransactionTag({
|
|
168
|
-
type: TRANSACTION_TYPES.UPDATE_REWARDS_DESTINATION,
|
|
169
|
-
walletAddress,
|
|
170
|
-
assetId,
|
|
171
|
-
destination,
|
|
172
|
-
lazyDistributors: lazyDistributors.join(","),
|
|
173
|
-
timestamp: Date.now(),
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
return {
|
|
177
|
-
transactionData: {
|
|
178
|
-
transactions: [
|
|
179
|
-
{
|
|
180
|
-
serializedTransaction,
|
|
181
|
-
metadata: {
|
|
182
|
-
type: TRANSACTION_TYPES.UPDATE_REWARDS_DESTINATION,
|
|
183
|
-
description: destinationExists
|
|
184
|
-
? `Update rewards destination to ${destination.slice(
|
|
185
|
-
0,
|
|
186
|
-
4,
|
|
187
|
-
)}...${destination.slice(-4)}`
|
|
188
|
-
: `Update rewards destination to ${destination.slice(
|
|
189
|
-
0,
|
|
190
|
-
4,
|
|
191
|
-
)}...${destination.slice(
|
|
192
|
-
-4,
|
|
193
|
-
)} (Warning: destination account does not exist)`,
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
],
|
|
197
|
-
parallel: false,
|
|
198
|
-
tag,
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { getHotspots } from "./procedures/getHotspots";
|
|
2
|
-
import { claimRewards } from "./procedures/claimRewards";
|
|
3
|
-
import { getPendingRewards } from "./procedures/getPendingRewards";
|
|
4
|
-
import { transferHotspot } from "./procedures/transferHotspot";
|
|
5
|
-
import { updateRewardsDestination } from "./procedures/updateRewardsDestination";
|
|
6
|
-
import { getSplit } from "./procedures/getSplit";
|
|
7
|
-
import { createSplit } from "./procedures/createSplit";
|
|
8
|
-
import { deleteSplit } from "./procedures/deleteSplit";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Hotspots router - handles all hotspot-related operations.
|
|
12
|
-
*/
|
|
13
|
-
export const hotspotsRouter = {
|
|
14
|
-
/** Get hotspots by wallet address with filtering and pagination */
|
|
15
|
-
getHotspots,
|
|
16
|
-
/** Create transactions to claim rewards for hotspots */
|
|
17
|
-
claimRewards,
|
|
18
|
-
/** Get pending rewards for all hotspots in a wallet */
|
|
19
|
-
getPendingRewards,
|
|
20
|
-
/** Create a transaction to transfer a hotspot to a new owner */
|
|
21
|
-
transferHotspot,
|
|
22
|
-
/** Update the rewards destination for a hotspot */
|
|
23
|
-
updateRewardsDestination,
|
|
24
|
-
/** Get the split configuration for a hotspot */
|
|
25
|
-
getSplit,
|
|
26
|
-
/** Create a split configuration for a hotspot */
|
|
27
|
-
createSplit,
|
|
28
|
-
/** Remove the split configuration from a hotspot */
|
|
29
|
-
deleteSplit,
|
|
30
|
-
};
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
// ============================================================================
|
|
4
|
-
// Input Schemas
|
|
5
|
-
// ============================================================================
|
|
6
|
-
|
|
7
|
-
export const HotspotTypeSchema = z.enum(["iot", "mobile", "all"]);
|
|
8
|
-
|
|
9
|
-
export const GetHotspotsInputSchema = z.object({
|
|
10
|
-
walletAddress: z.string().min(32),
|
|
11
|
-
type: HotspotTypeSchema.optional(),
|
|
12
|
-
page: z.coerce.number().int().min(1).default(1),
|
|
13
|
-
limit: z.coerce.number().int().min(1).max(100).default(10),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const ClaimRewardsInputSchema = z.object({
|
|
17
|
-
walletAddress: z.string().min(32),
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export const GetPendingRewardsInputSchema = z.object({
|
|
21
|
-
walletAddress: z.string().min(32),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
export const TransferHotspotInputSchema = z.object({
|
|
25
|
-
walletAddress: z.string().min(32),
|
|
26
|
-
hotspotPubkey: z.string().min(1),
|
|
27
|
-
recipient: z.string().min(32),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
export const UpdateRewardsDestinationInputSchema = z.object({
|
|
31
|
-
walletAddress: z.string().min(32),
|
|
32
|
-
hotspotPubkey: z.string().min(1),
|
|
33
|
-
destination: z.string().min(32),
|
|
34
|
-
lazyDistributors: z.array(z.string().min(32)).min(1),
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
export const GetSplitInputSchema = z.object({
|
|
38
|
-
walletAddress: z.string().min(32),
|
|
39
|
-
hotspotPubkey: z.string().min(1),
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
export const RewardSplitInputSchema = z.object({
|
|
43
|
-
address: z.string().min(32),
|
|
44
|
-
type: z.enum(["percentage", "fixed"]),
|
|
45
|
-
amount: z.number(),
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
export const ScheduleInputSchema = z.object({
|
|
49
|
-
frequency: z.enum(["daily", "weekly", "monthly"]),
|
|
50
|
-
time: z.string(),
|
|
51
|
-
timezone: z.string(),
|
|
52
|
-
dayOfWeek: z.string().optional(),
|
|
53
|
-
dayOfMonth: z.string().optional(),
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
export const CreateSplitInputSchema = z.object({
|
|
57
|
-
walletAddress: z.string().min(32),
|
|
58
|
-
hotspotPubkey: z.string().min(1),
|
|
59
|
-
rewardsSplit: z.array(RewardSplitInputSchema),
|
|
60
|
-
schedule: ScheduleInputSchema,
|
|
61
|
-
lazyDistributor: z.string().min(32),
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
export const DeleteSplitInputSchema = z.object({
|
|
65
|
-
walletAddress: z.string().min(32),
|
|
66
|
-
hotspotPubkey: z.string().min(1),
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// ============================================================================
|
|
70
|
-
// Output Schemas
|
|
71
|
-
// ============================================================================
|
|
72
|
-
|
|
73
|
-
export const DeviceTypeSchema = z.enum([
|
|
74
|
-
"iot-gateway",
|
|
75
|
-
"wifiIndoor",
|
|
76
|
-
"wifiOutdoor",
|
|
77
|
-
"wifiDataOnly",
|
|
78
|
-
"cbrs",
|
|
79
|
-
]);
|
|
80
|
-
|
|
81
|
-
export const HotspotSharesSchema = z.object({
|
|
82
|
-
fixed: z.string().optional(),
|
|
83
|
-
percentage: z.number().optional(),
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
export const HotspotSchema = z.object({
|
|
87
|
-
address: z.string(),
|
|
88
|
-
entityKey: z.string(),
|
|
89
|
-
name: z.string(),
|
|
90
|
-
type: HotspotTypeSchema,
|
|
91
|
-
deviceType: DeviceTypeSchema,
|
|
92
|
-
city: z.string().optional(),
|
|
93
|
-
state: z.string().optional(),
|
|
94
|
-
country: z.string().optional(),
|
|
95
|
-
asset: z.string(),
|
|
96
|
-
isOnline: z.boolean().optional(),
|
|
97
|
-
owner: z.string().optional(),
|
|
98
|
-
shares: HotspotSharesSchema.optional(),
|
|
99
|
-
ownershipType: z.string(),
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
export const HotspotsDataSchema = z.object({
|
|
103
|
-
hotspots: z.array(HotspotSchema),
|
|
104
|
-
total: z.number(),
|
|
105
|
-
page: z.number(),
|
|
106
|
-
totalPages: z.number(),
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
export const TransactionMetadataSchema = z
|
|
110
|
-
.object({
|
|
111
|
-
type: z.string(),
|
|
112
|
-
description: z.string(),
|
|
113
|
-
})
|
|
114
|
-
.catchall(z.unknown());
|
|
115
|
-
|
|
116
|
-
export const TransactionItemSchema = z.object({
|
|
117
|
-
serializedTransaction: z.string(),
|
|
118
|
-
metadata: TransactionMetadataSchema.optional(),
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
export const TransactionDataSchema = z.object({
|
|
122
|
-
transactions: z.array(TransactionItemSchema),
|
|
123
|
-
parallel: z.boolean(),
|
|
124
|
-
tag: z.string().optional(),
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
export const ClaimRewardsOutputSchema = z.object({
|
|
128
|
-
transactionData: TransactionDataSchema,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
export const TransferHotspotOutputSchema = z.object({
|
|
132
|
-
transactionData: TransactionDataSchema,
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
export const UpdateRewardsDestinationOutputSchema = z.object({
|
|
136
|
-
transactionData: TransactionDataSchema,
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
export const SplitShareSchema = z.object({
|
|
140
|
-
wallet: z.string(),
|
|
141
|
-
delegate: z.string(),
|
|
142
|
-
fixed: z.number(),
|
|
143
|
-
shares: z.number(),
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
export const SplitResponseSchema = z.object({
|
|
147
|
-
walletAddress: z.string(),
|
|
148
|
-
hotspotPubkey: z.string(),
|
|
149
|
-
splitAddress: z.string(),
|
|
150
|
-
shares: z.array(SplitShareSchema),
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
export const CreateSplitOutputSchema = z.object({
|
|
154
|
-
transactionData: TransactionDataSchema,
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
export const DeleteSplitOutputSchema = z.object({
|
|
158
|
-
transactionData: TransactionDataSchema,
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
// Pending rewards - proxied from oracle, so we use any for flexibility
|
|
162
|
-
export const PendingRewardsOutputSchema = z.any();
|
|
163
|
-
|
|
164
|
-
// ============================================================================
|
|
165
|
-
// Type Exports
|
|
166
|
-
// ============================================================================
|
|
167
|
-
|
|
168
|
-
export type GetHotspotsInput = z.infer<typeof GetHotspotsInputSchema>;
|
|
169
|
-
export type ClaimRewardsInput = z.infer<typeof ClaimRewardsInputSchema>;
|
|
170
|
-
export type GetPendingRewardsInput = z.infer<
|
|
171
|
-
typeof GetPendingRewardsInputSchema
|
|
172
|
-
>;
|
|
173
|
-
export type TransferHotspotInput = z.infer<typeof TransferHotspotInputSchema>;
|
|
174
|
-
export type UpdateRewardsDestinationInput = z.infer<
|
|
175
|
-
typeof UpdateRewardsDestinationInputSchema
|
|
176
|
-
>;
|
|
177
|
-
export type GetSplitInput = z.infer<typeof GetSplitInputSchema>;
|
|
178
|
-
export type CreateSplitInput = z.infer<typeof CreateSplitInputSchema>;
|
|
179
|
-
export type DeleteSplitInput = z.infer<typeof DeleteSplitInputSchema>;
|
|
180
|
-
export type HotspotsData = z.infer<typeof HotspotsDataSchema>;
|
|
181
|
-
export type Hotspot = z.infer<typeof HotspotSchema>;
|
|
182
|
-
export type SplitResponse = z.infer<typeof SplitResponseSchema>;
|