@asterkit/core
v0.1.3
Published
TypeScript SDK for Aster agent and builder management APIs.
Maintainers
Readme
@asterkit/core
TypeScript SDK for Aster agent and builder management APIs.
Install
From the monorepo root:
bun installFrom another project:
bun add @asterkit/core viemWhat This Package Exposes
@asterkit/core exports:
- Agent APIs:
approveAgent,getAgents,updateAgent,deleteAgent - Builder APIs:
approveBuilder,getBuilders,updateBuilder,deleteBuilder - Utilities/config/constants used by the APIs
Defaults
- Host:
https://fapi.asterdex.com - Aster chain:
Mainnet - Signature chain id:
56 - Default agent name (if omitted):
AsterKit
Quick Start
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { bsc } from "viem/chains";
import { approveAgent, getAgents } from "@asterkit/core";
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const walletClient = createWalletClient({
account,
chain: bsc,
transport: http(),
});
const approved = await approveAgent({
walletClient,
agentAddress: "0x1111111111111111111111111111111111111111",
canSpotTrade: true,
canPerpTrade: true,
canWithdraw: false,
});
const agents = await getAgents({
walletClient,
user: account.address,
signer: account.address,
});
console.log(approved.status, agents.data);Agent API
approveAgent(options)
Registers an agent with permissions.
Required:
walletClientagentAddress
Optional:
agentName,ipWhitelist,expiredcanSpotTrade,canPerpTrade,canWithdrawhost,signatureChainId,asterChain,nonce
getAgents(options)
Fetches agents for a user/signer pair.
Required:
usersigner- and either
signatureorwalletClient(to sign query string)
Optional:
host,asterChain,nonce
updateAgent(options)
Updates permissions on an existing agent.
Required:
walletClientagentAddresscanSpotTradecanPerpTradecanWithdraw
Optional:
ipWhitelist,host,signatureChainId,asterChain,nonce
deleteAgent(options)
Deletes an existing agent.
Required:
walletClientagentAddress
Optional:
host,signatureChainId,asterChain,nonce
Builder API
approveBuilder(options)
Registers a builder.
Required:
walletClientbuildermaxFeeRatebuilderName
Optional:
host,signatureChainId,asterChain,nonce
getBuilders(options)
Fetches builders for a user/signer pair.
Required:
usersigner- and either
signatureorwalletClient(to sign query string)
Optional:
host,asterChain,nonce
updateBuilder(options)
Updates a builder.
Required:
walletClientbuildermaxFeeRate
Optional:
host,signatureChainId,asterChain,nonce
deleteBuilder(options)
Deletes a builder.
Required:
walletClientbuilder
Optional:
host,signatureChainId,asterChain,nonce
Error Handling
API calls throw AsterRequestError when the HTTP status is not successful.
import { AsterRequestError, approveBuilder } from "@asterkit/core";
try {
await approveBuilder({
walletClient,
builder: "0x2222222222222222222222222222222222222222",
maxFeeRate: "10",
builderName: "my-builder",
});
} catch (error) {
if (error instanceof AsterRequestError) {
console.error(error.status, error.url, error.data);
}
}Development
From repo root:
bun install
bun test packages/core/src/*.test.ts
bun test packages/core/src/*.integration.test.ts
bun run --cwd packages/core build