Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/examples/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ async function example() {
amount: '10',
fromChain: BlockchainType.SVM,
toChain: BlockchainType.SVM,
reason:
"Strong upward momentum in the market combined with positive news on this token's ecosystem growth",
});
console.log('SOL Trade Result:', solTrade);

Expand All @@ -478,6 +480,8 @@ async function example() {
toChain: BlockchainType.EVM,
fromSpecificChain: SpecificChain.ETH,
toSpecificChain: SpecificChain.ETH,
reason:
"Strong upward momentum in the market combined with positive news on this token's ecosystem growth",
});
console.log('ETH Trade Result:', ethTrade);

Expand All @@ -488,6 +492,8 @@ async function example() {
amount: '100',
fromChain: BlockchainType.SVM,
toChain: BlockchainType.SVM,
reason:
"Strong upward momentum in the market combined with positive news on this token's ecosystem growth",
});
console.log('Trade Quote:', quote);

Expand Down
6 changes: 6 additions & 0 deletions docs/examples/execute-trade-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ switch (tradeType) {
toChain: BlockchainType.EVM, // Blockchain type for destination token
fromSpecificChain: SpecificChain.ETH, // Specific chain for source token (eth, polygon, etc)
toSpecificChain: SpecificChain.ETH, // Specific chain for destination token
reason:
"Strong upward momentum in the market combined with positive news on this token's ecosystem growth",
};
console.log('Executing Ethereum trade: Buy ETH with USDC on Ethereum');
break;
Expand All @@ -67,6 +69,8 @@ switch (tradeType) {
toChain: BlockchainType.EVM, // Blockchain type for destination token (evm)
fromSpecificChain: SpecificChain.SVM, // Specific chain for source token (Solana)
toSpecificChain: SpecificChain.ETH, // Specific chain for destination token (Ethereum)
reason:
"Strong upward momentum in the market combined with positive news on this token's ecosystem growth",
};
console.log('Executing cross-chain trade: Buy ETH with Solana USDC');
break;
Expand All @@ -83,6 +87,8 @@ switch (tradeType) {
toChain: BlockchainType.SVM, // Blockchain type for destination token
fromSpecificChain: SpecificChain.SVM, // Specific chain for source token
toSpecificChain: SpecificChain.SVM, // Specific chain for destination token
reason:
"Strong upward momentum in the market combined with positive news on this token's ecosystem growth",
};
console.log('Executing Solana trade: Buy SOL with USDC on Solana');
break;
Expand Down
8 changes: 8 additions & 0 deletions docs/examples/multi-chain-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ async function executeMultiChainTrades(client: TradingSimulatorClient): Promise<
slippageTolerance: '0.5',
fromChain: BlockchainType.SVM,
toChain: BlockchainType.SVM,
reason:
"Strong upward momentum in the market combined with positive news on this token's ecosystem growth",
};

const solTrade: TradeResponse = await client.executeTrade(solanaTradeDetails);
Expand All @@ -154,6 +156,8 @@ async function executeMultiChainTrades(client: TradingSimulatorClient): Promise<
toChain: BlockchainType.EVM,
fromSpecificChain: SpecificChain.ETH,
toSpecificChain: SpecificChain.ETH,
reason:
"Strong upward momentum in the market combined with positive news on this token's ecosystem growth",
};

const ethTrade: TradeResponse = await client.executeTrade(ethereumTradeDetails);
Expand Down Expand Up @@ -181,6 +185,8 @@ async function executeCrossChainTrades(client: TradingSimulatorClient): Promise<
toChain: BlockchainType.EVM,
fromSpecificChain: SpecificChain.SVM,
toSpecificChain: SpecificChain.ETH,
reason:
"Strong upward momentum in the market combined with positive news on this token's ecosystem growth",
};

const crossTrade1: TradeResponse = await client.executeTrade(crossChainTradeDetails1);
Expand All @@ -204,6 +210,8 @@ async function executeCrossChainTrades(client: TradingSimulatorClient): Promise<
toChain: BlockchainType.SVM,
fromSpecificChain: SpecificChain.ETH,
toSpecificChain: SpecificChain.SVM,
reason:
"Strong upward momentum in the market combined with positive news on this token's ecosystem growth",
};

const crossTrade2: TradeResponse = await client.executeTrade(crossChainTradeDetails2);
Expand Down
19 changes: 18 additions & 1 deletion docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,10 @@
"type": "string",
"description": "Error message if the trade failed"
},
"reason": {
"type": "string",
"description": "Reason provided for executing the trade"
},
"timestamp": {
"type": "string",
"format": "date-time",
Expand Down Expand Up @@ -2754,7 +2758,7 @@
"application/json": {
"schema": {
"type": "object",
"required": ["fromToken", "toToken", "amount"],
"required": ["fromToken", "toToken", "amount", "reason"],
"properties": {
"fromToken": {
"type": "string",
Expand All @@ -2771,6 +2775,11 @@
"description": "Amount of fromToken to trade",
"example": "1.5"
},
"reason": {
"type": "string",
"description": "Reason for executing this trade",
"example": "Strong upward momentum in the market combined with positive news on this token's ecosystem growth."
},
"slippageTolerance": {
"type": "string",
"description": "Optional slippage tolerance in percentage",
Expand Down Expand Up @@ -2852,6 +2861,14 @@
"type": "boolean",
"description": "Whether the trade was successfully completed"
},
"error": {
"type": "string",
"description": "Error message if the trade failed"
},
"reason": {
"type": "string",
"description": "Reason provided for executing the trade"
},
"timestamp": {
"type": "string",
"format": "date-time",
Expand Down
6 changes: 6 additions & 0 deletions e2e/tests/base-trades.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ console.log(`- Imported config from ../../src/config has initial balances:`, {
});
console.log('===========================================================\n');

const reason = 'base-trades end to end tests';

describe('Base Chain Trading', () => {
let adminApiKey: string;

Expand Down Expand Up @@ -169,6 +171,7 @@ describe('Base Chain Trading', () => {
toChain: BlockchainType.EVM,
fromSpecificChain: SpecificChain.BASE,
toSpecificChain: SpecificChain.BASE,
reason,
})) as TradeResponse;

console.log(`Trade response for ${token.address}: ${JSON.stringify(tradeResponse.success)}`);
Expand Down Expand Up @@ -326,6 +329,7 @@ describe('Base Chain Trading', () => {
toChain: BlockchainType.EVM,
fromSpecificChain: SpecificChain.BASE,
toSpecificChain: SpecificChain.ETH, // Different chain from fromSpecificChain
reason,
});

// If we get here, the trade might have succeeded, which is unexpected if cross-chain trading is disabled
Expand Down Expand Up @@ -494,6 +498,7 @@ describe('Base Chain Trading', () => {
toChain: BlockchainType.EVM,
fromSpecificChain: SpecificChain.BASE,
toSpecificChain: SpecificChain.BASE,
reason,
});

expect(tradeResponse.success).toBe(false); // The test should fail here if excessive trading is allowed
Expand Down Expand Up @@ -528,6 +533,7 @@ describe('Base Chain Trading', () => {
toChain: BlockchainType.EVM,
fromSpecificChain: SpecificChain.BASE,
toSpecificChain: SpecificChain.BASE,
reason,
})) as TradeResponse;

// This trade should succeed
Expand Down
3 changes: 3 additions & 0 deletions e2e/tests/chainSpecific.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { getPool } from '../utils/db-manager';
import { BalancesResponse } from '../utils/api-types';
import { config } from '../../src/config';

const reason = 'chainSpecific end to end tests';

describe('Specific Chains', () => {
let adminApiKey: string;

Expand Down Expand Up @@ -140,6 +142,7 @@ describe('Specific Chains', () => {
fromToken: ethToken,
toToken: usdcToken,
amount: tradeAmount,
reason,
});
expect(tradeResponse.success).toBe(true);

Expand Down
4 changes: 4 additions & 0 deletions e2e/tests/deactivate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ describe('Team Deactivation API', () => {
amount: '100',
fromChain: BlockchainType.SVM,
toChain: BlockchainType.SVM,
reason,
});
// Should not reach here - trade should be blocked
expect(false).toBe(true); // Force test to fail if we get here
Expand Down Expand Up @@ -251,6 +252,7 @@ describe('Team Deactivation API', () => {
amount: '100',
fromChain: BlockchainType.SVM,
toChain: BlockchainType.SVM,
reason: 'inactive teams are filtered from leaderboard',
});

// Have the other teams make trades too to populate leaderboard
Expand All @@ -260,6 +262,7 @@ describe('Team Deactivation API', () => {
amount: '50',
fromChain: BlockchainType.SVM,
toChain: BlockchainType.SVM,
reason: 'inactive teams are filtered from leaderboard',
});

await teamClient2.executeTrade({
Expand All @@ -268,6 +271,7 @@ describe('Team Deactivation API', () => {
amount: '75',
fromChain: BlockchainType.SVM,
toChain: BlockchainType.SVM,
reason: 'inactive teams are filtered from leaderboard',
});

// Wait a moment for portfolio values to update
Expand Down
17 changes: 11 additions & 6 deletions e2e/tests/multi-team-competition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ErrorResponse,
LeaderboardResponse,
SnapshotResponse,
SpecificChain,
TeamProfileResponse,
TradeResponse,
} from '../utils/api-types';
Expand Down Expand Up @@ -59,6 +60,8 @@ describe('Multi-Team Competition', () => {
let adminClient: ApiClient;
let competitionId: string;

const reason = 'multi-team-competition end-to-end test';

// Clean up test state before each test
beforeEach(async () => {
await cleanupTestState();
Expand Down Expand Up @@ -294,14 +297,15 @@ describe('Multi-Team Competition', () => {
console.log(`Team ${i + 1} trading ${tradeAmount} USDC for token ${tokenToTrade}`);

// Execute trade using the client - each team buys a different BASE token with 100 USDC
const tradeResponse = (await team.client.request('post', '/api/trade/execute', {
const tradeResponse = (await team.client.executeTrade({
fromToken: BASE_USDC_ADDRESS,
toToken: tokenToTrade,
amount: tradeAmount.toString(),
fromChain: BlockchainType.EVM,
toChain: BlockchainType.EVM,
fromSpecificChain: BASE_CHAIN,
toSpecificChain: BASE_CHAIN,
fromSpecificChain: SpecificChain.BASE,
toSpecificChain: SpecificChain.BASE,
reason,
})) as TradeResponse;

// Verify trade was successful
Expand Down Expand Up @@ -447,14 +451,15 @@ describe('Multi-Team Competition', () => {
);

// Execute trade - each team buys a different BASE token with USDC
const tradeResponse = (await team.client.request('post', '/api/trade/execute', {
const tradeResponse = (await team.client.executeTrade({
fromToken: BASE_USDC_ADDRESS,
toToken: tokenToTrade,
amount: tradeAmount.toString(),
fromChain: BlockchainType.EVM,
toChain: BlockchainType.EVM,
fromSpecificChain: BASE_CHAIN,
toSpecificChain: BASE_CHAIN,
fromSpecificChain: SpecificChain.BASE,
toSpecificChain: SpecificChain.BASE,
reason,
})) as TradeResponse;

// Verify trade was successful
Expand Down
3 changes: 3 additions & 0 deletions e2e/tests/portfolio-snapshots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { BlockchainType } from '../../src/types';
import { PriceTracker } from '../../src/services/price-tracker.service';
import { BalancesResponse, SnapshotResponse, TokenPortfolioItem } from '../utils/api-types';

const reason = 'portfolio-snapshots end-to-end tests';

describe('Portfolio Snapshots', () => {
let adminApiKey: string;

Expand Down Expand Up @@ -174,6 +176,7 @@ describe('Portfolio Snapshots', () => {
amount: '100',
fromChain: BlockchainType.SVM,
toChain: BlockchainType.SVM,
reason,
});

// Wait for trade to process
Expand Down
Loading