UNPKG

axie-tools

Version:

TypeScript library and CLI tool for interacting with Axie Infinity marketplace and NFTs on Ronin network. Features marketplace operations (buy/sell/delist), batch transfers, and wallet information.

197 lines (177 loc) 4.34 kB
import { apiRequest } from '../utils'; interface GraphQLResponse<T> { data: T; errors?: Array<{ message: string }>; } interface DelegateAtiaBlessingResponse { delegateAtiaBlessing: { delegatedAt: number; }; } interface AtiaBlessingDelegation { delegatedAt: number; delegatorSlipsPercent: number; fromAddress: string; toAddress: string; lastPrayedAt: string; fromProfile?: { name: string; }; toProfile?: { name: string; accountId: string; addresses: { ronin: string; }[]; }; } interface GetAtiaBlessingDelegationsResponse { atiaBlessingDelegations: AtiaBlessingDelegation[]; } const GRAPHQL_ENDPOINT = 'https://graphql-gateway.axieinfinity.com/graphql'; export async function delegateAtiaBlessing( accessToken: string, signature: string, userAddress: string, toAddress: string, delegatedAt: number, delegatorSlipsPercent: number ): Promise<boolean> { const query = ` mutation DelegateAtiaBlessing( $toAddress: String!, $delegatorSlipsPercent: Int!, $delegatedAt: Int!, $signature: String!, $userAddress: String! ) { delegateAtiaBlessing( toAddress: $toAddress delegatorSlipsPercent: $delegatorSlipsPercent delegatedAt: $delegatedAt signature: $signature userAddress: $userAddress ) { delegatedAt } } `; const variables = { toAddress, delegatorSlipsPercent, delegatedAt, signature, userAddress }; try { const result = await apiRequest<GraphQLResponse<DelegateAtiaBlessingResponse>>( GRAPHQL_ENDPOINT, JSON.stringify({ query, variables }), { 'Authorization': `Bearer ${accessToken}` } ); if (result.errors) { console.error('❌ GraphQL Error:', result.errors[0].message); return false; } return true; } catch (error) { console.error('❌ Network Error:', error); return false; } } export async function getAtiaBlessingDelegations( accessToken: string, userAddress: string, isDelegating = true, isDelegated = true ): Promise<AtiaBlessingDelegation[]> { const query = ` query GetAtiaBlessingDelegations( $userAddress: String!, $isDelegating: Boolean!, $isDelegated: Boolean! ) { atiaBlessingDelegations( userAddress: $userAddress isDelegating: $isDelegating isDelegated: $isDelegated ) { delegatedAt delegatorSlipsPercent fromAddress toAddress lastPrayedAt fromProfile { name } toProfile { name accountId addresses { ronin } } } } `; const variables = { userAddress, isDelegating, isDelegated }; try { const result = await apiRequest<GraphQLResponse<GetAtiaBlessingDelegationsResponse>>( GRAPHQL_ENDPOINT, JSON.stringify({ query, variables }), { 'Authorization': `Bearer ${accessToken}` } ); if (result.errors) { console.error('❌ GraphQL Error:', result.errors[0].message); return []; } return result.data.atiaBlessingDelegations; } catch (error) { console.error('❌ Network Error:', error); return []; } } export async function revokeAtiaBlessingDelegation( accessToken: string, userAddress: string, toAddress: string, fromAddress: string ): Promise<boolean> { const query = ` mutation RevokeAtiaBlessingDelegation( $userAddress: String!, $toAddress: String!, $fromAddress: String! ) { revokeAtiaBlessingDelegation( userAddress: $userAddress toAddress: $toAddress fromAddress: $fromAddress ) } `; const variables = { userAddress, toAddress, fromAddress }; try { const result = await apiRequest<GraphQLResponse<{ revokeAtiaBlessingDelegation: boolean }>>( GRAPHQL_ENDPOINT, JSON.stringify({ query, variables }), { 'Authorization': `Bearer ${accessToken}` } ); if (result.errors) { console.error('❌ GraphQL Error:', result.errors[0].message); return false; } return result.data.revokeAtiaBlessingDelegation; } catch (error) { console.error('❌ Network Error:', error); return false; } }