Rollback proxy
This commit is contained in:
179
src/Managing.Web3Proxy/package-lock.json
generated
179
src/Managing.Web3Proxy/package-lock.json
generated
@@ -9,7 +9,6 @@
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.5.6",
|
||||
"@fastify/autoload": "^6.0.0",
|
||||
"@fastify/cookie": "^11.0.1",
|
||||
"@fastify/cors": "^11.0.0",
|
||||
@@ -36,8 +35,6 @@
|
||||
"fastify-cli": "^7.3.0",
|
||||
"fastify-plugin": "^5.0.1",
|
||||
"form-data": "^4.0.1",
|
||||
"graphql": "^16.11.0",
|
||||
"graphql-tag": "^2.12.6",
|
||||
"knex": "^3.1.0",
|
||||
"mysql2": "^3.11.3",
|
||||
"postgrator": "^8.0.0",
|
||||
@@ -61,39 +58,6 @@
|
||||
"version": "1.11.0",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@apollo/client": {
|
||||
"version": "3.5.6",
|
||||
"resolved": "https://registry.npmjs.org/@apollo/client/-/client-3.5.6.tgz",
|
||||
"integrity": "sha512-XHoouuEJ4L37mtfftcHHO1caCRrKKAofAwqRoq28UQIPMJk+e7n3X9OtRRNXKk/9tmhNkwelSary+EilfPwI7A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@graphql-typed-document-node/core": "^3.0.0",
|
||||
"@wry/context": "^0.6.0",
|
||||
"@wry/equality": "^0.5.0",
|
||||
"@wry/trie": "^0.3.0",
|
||||
"graphql-tag": "^2.12.3",
|
||||
"hoist-non-react-statics": "^3.3.2",
|
||||
"optimism": "^0.16.1",
|
||||
"prop-types": "^15.7.2",
|
||||
"symbol-observable": "^4.0.0",
|
||||
"ts-invariant": "^0.9.4",
|
||||
"tslib": "^2.3.0",
|
||||
"zen-observable-ts": "^1.2.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
|
||||
"react": "^16.8.0 || ^17.0.0",
|
||||
"subscriptions-transport-ws": "^0.9.0 || ^0.11.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"react": {
|
||||
"optional": true
|
||||
},
|
||||
"subscriptions-transport-ws": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/runtime": {
|
||||
"version": "7.26.10",
|
||||
"license": "MIT",
|
||||
@@ -662,15 +626,6 @@
|
||||
"fastify-plugin": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@graphql-typed-document-node/core": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@graphql-typed-document-node/core/-/core-3.2.0.tgz",
|
||||
"integrity": "sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@humanfs/core": {
|
||||
"version": "0.19.1",
|
||||
"dev": true,
|
||||
@@ -2093,42 +2048,6 @@
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@wry/context": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@wry/context/-/context-0.6.1.tgz",
|
||||
"integrity": "sha512-LOmVnY1iTU2D8tv4Xf6MVMZZ+juIJ87Kt/plMijjN20NMAXGmH4u8bS1t0uT74cZ5gwpocYueV58YwyI8y+GKw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "^2.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/@wry/equality": {
|
||||
"version": "0.5.7",
|
||||
"resolved": "https://registry.npmjs.org/@wry/equality/-/equality-0.5.7.tgz",
|
||||
"integrity": "sha512-BRFORjsTuQv5gxcXsuDXx6oGRhuVsEGwZy6LOzRRfgu+eSfxbhUQ9L9YtSEIuIjY/o7g3iWFjrc5eSY1GXP2Dw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "^2.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/@wry/trie": {
|
||||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@wry/trie/-/trie-0.3.2.tgz",
|
||||
"integrity": "sha512-yRTyhWSls2OY/pYLfwff867r8ekooZ4UI+/gxot5Wj8EFwSf2rG+n+Mo/6LoLQm1TKA4GRj2+LCpbfS937dClQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "^2.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/abitype": {
|
||||
"version": "1.0.8",
|
||||
"license": "MIT",
|
||||
@@ -2873,8 +2792,6 @@
|
||||
},
|
||||
"node_modules/cross-fetch": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.1.0.tgz",
|
||||
"integrity": "sha512-uKm5PU+MHTootlWEY+mZ4vvXoCn4fLQxT9dSc1sXVMSFkINTJVN8cAQROpwcKm8bJ/c7rgZVIBWzH5T78sNZZw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"node-fetch": "^2.7.0"
|
||||
@@ -4534,30 +4451,6 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/graphql": {
|
||||
"version": "16.11.0",
|
||||
"resolved": "https://registry.npmjs.org/graphql/-/graphql-16.11.0.tgz",
|
||||
"integrity": "sha512-mS1lbMsxgQj6hge1XZ6p7GPhbrtFwUFYi3wRzXAC/FmYnyXMTvvI3td3rjmQ2u8ewXueaSvRPWaEcgVVOT9Jnw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/graphql-tag": {
|
||||
"version": "2.12.6",
|
||||
"resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.12.6.tgz",
|
||||
"integrity": "sha512-FdSNcu2QQcWnM2VNvSCCDCVS5PpPqpzgFT8+GXzqJuoDd0CBncxCY278u4mhRO7tMgo2JjgJA5aZ+nWSQ/Z+xg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "^2.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/has-bigints": {
|
||||
"version": "1.1.0",
|
||||
"dev": true,
|
||||
@@ -4683,15 +4576,6 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/hoist-non-react-statics": {
|
||||
"version": "3.3.2",
|
||||
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz",
|
||||
"integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"react-is": "^16.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/html-escaper": {
|
||||
"version": "2.0.2",
|
||||
"dev": true,
|
||||
@@ -5376,6 +5260,7 @@
|
||||
},
|
||||
"node_modules/js-tokens": {
|
||||
"version": "4.0.0",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
@@ -5610,6 +5495,7 @@
|
||||
},
|
||||
"node_modules/loose-envify": {
|
||||
"version": "1.4.0",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"js-tokens": "^3.0.0 || ^4.0.0"
|
||||
@@ -5905,6 +5791,7 @@
|
||||
},
|
||||
"node_modules/object-assign": {
|
||||
"version": "4.1.1",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
@@ -6017,28 +5904,6 @@
|
||||
"version": "12.1.3",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/optimism": {
|
||||
"version": "0.16.2",
|
||||
"resolved": "https://registry.npmjs.org/optimism/-/optimism-0.16.2.tgz",
|
||||
"integrity": "sha512-zWNbgWj+3vLEjZNIh/okkY2EUfX+vB9TJopzIZwT1xxaMqC5hRLLraePod4c5n4He08xuXNH+zhKFFCu390wiQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@wry/context": "^0.7.0",
|
||||
"@wry/trie": "^0.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/optimism/node_modules/@wry/context": {
|
||||
"version": "0.7.4",
|
||||
"resolved": "https://registry.npmjs.org/@wry/context/-/context-0.7.4.tgz",
|
||||
"integrity": "sha512-jmT7Sb4ZQWI5iyu3lobQxICu2nC/vbUhP0vIdd6tHC9PTfenmRmuIFqktc6GH9cgi+ZHnsLWPvfSvc4DrYmKiQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "^2.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/optionator": {
|
||||
"version": "0.9.4",
|
||||
"dev": true,
|
||||
@@ -6515,6 +6380,7 @@
|
||||
},
|
||||
"node_modules/prop-types": {
|
||||
"version": "15.8.1",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"loose-envify": "^1.4.0",
|
||||
@@ -6582,6 +6448,7 @@
|
||||
},
|
||||
"node_modules/react-is": {
|
||||
"version": "16.13.1",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/readable-stream": {
|
||||
@@ -7430,15 +7297,6 @@
|
||||
"whatwg-fetch": "^3.4.1"
|
||||
}
|
||||
},
|
||||
"node_modules/symbol-observable": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz",
|
||||
"integrity": "sha512-b19dMThMV4HVFynSAM1++gBHAbk2Tc/osgLIBZMKsyqh34jb2e8Os7T6ZW/Bt3pJFdBTd2JwAnAAEQV7rSNvcQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/tapable": {
|
||||
"version": "2.2.1",
|
||||
"dev": true,
|
||||
@@ -7662,18 +7520,6 @@
|
||||
"version": "2.1.0",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/ts-invariant": {
|
||||
"version": "0.9.4",
|
||||
"resolved": "https://registry.npmjs.org/ts-invariant/-/ts-invariant-0.9.4.tgz",
|
||||
"integrity": "sha512-63jtX/ZSwnUNi/WhXjnK8kz4cHHpYS60AnmA6ixz17l7E12a5puCWFlNpkne5Rl0J8TBPVHpGjsj4fxs8ObVLQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "^2.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.8.1",
|
||||
"license": "0BSD"
|
||||
@@ -8426,21 +8272,6 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/zen-observable": {
|
||||
"version": "0.8.15",
|
||||
"resolved": "https://registry.npmjs.org/zen-observable/-/zen-observable-0.8.15.tgz",
|
||||
"integrity": "sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/zen-observable-ts": {
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://registry.npmjs.org/zen-observable-ts/-/zen-observable-ts-1.2.5.tgz",
|
||||
"integrity": "sha512-QZWQekv6iB72Naeake9hS1KxHlotfRpe+WGNbNx5/ta+R3DNjVO2bswf63gXlWDcs+EMd7XY8HfVQyP1X6T4Zg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"zen-observable": "0.8.15"
|
||||
}
|
||||
},
|
||||
"node_modules/zod": {
|
||||
"version": "3.24.2",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
"author": "Oda",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.5.6",
|
||||
"@fastify/autoload": "^6.0.0",
|
||||
"@fastify/cookie": "^11.0.1",
|
||||
"@fastify/cors": "^11.0.0",
|
||||
@@ -55,8 +54,6 @@
|
||||
"fastify-cli": "^7.3.0",
|
||||
"fastify-plugin": "^5.0.1",
|
||||
"form-data": "^4.0.1",
|
||||
"graphql": "^16.11.0",
|
||||
"graphql-tag": "^2.12.6",
|
||||
"knex": "^3.1.0",
|
||||
"mysql2": "^3.11.3",
|
||||
"postgrator": "^8.0.0",
|
||||
|
||||
@@ -114,7 +114,7 @@ export function createDecreaseEncodedPayload({
|
||||
callbackContract: zeroAddress,
|
||||
market: p.marketAddress,
|
||||
swapPath: p.swapPath,
|
||||
uiFeeReceiver: zeroAddress,
|
||||
uiFeeReceiver: "0xF9f04a745Db54B25bB8B345a1da74D4E3c38c8aB",
|
||||
},
|
||||
numbers: {
|
||||
sizeDeltaUsd: p.sizeDeltaUsd,
|
||||
|
||||
@@ -244,7 +244,7 @@ function createOrderParams({
|
||||
callbackContract: zeroAddress,
|
||||
market: p.marketAddress,
|
||||
swapPath: p.swapPath,
|
||||
uiFeeReceiver: zeroAddress,
|
||||
uiFeeReceiver: "0xF9f04a745Db54B25bB8B345a1da74D4E3c38c8aB",
|
||||
},
|
||||
numbers: {
|
||||
sizeDeltaUsd: p.sizeDeltaUsd,
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import {claimGmxFundingFeesImpl, getClientForAddress} from '../../src/plugins/custom/gmx.js';
|
||||
|
||||
test('GMX Claim Funding Fees', async (t) => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f';
|
||||
|
||||
await t.test('should claim funding fees for valid account', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await claimGmxFundingFeesImpl(sdk);
|
||||
|
||||
console.log('Claim funding fees result:', result);
|
||||
assert.ok(typeof result === 'string', 'Result should be a string');
|
||||
assert.ok(result.length > 0, 'Result should not be empty');
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
// Expected behavior - may fail if no claimable fees or in test environment
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
|
||||
// Check for expected error messages
|
||||
const errorMessage = error.message;
|
||||
const expectedErrors = [
|
||||
'No funding fees available to claim',
|
||||
'Failed to claim funding fees',
|
||||
'No markets info data available'
|
||||
];
|
||||
|
||||
const hasExpectedError = expectedErrors.some(expectedError =>
|
||||
errorMessage.includes(expectedError)
|
||||
);
|
||||
|
||||
if (!hasExpectedError) {
|
||||
// Log unexpected errors for debugging
|
||||
console.warn('Unexpected error in claimGmxFundingFeesImpl:', errorMessage);
|
||||
}
|
||||
|
||||
// Still assert it's an error for test completeness
|
||||
assert.ok(true, 'Expected error occurred');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,119 +0,0 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import {claimGmxPriceImpactImpl, getClientForAddress} from '../../src/plugins/custom/gmx.js';
|
||||
|
||||
test('GMX Claim Price Impact', async (t) => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f';
|
||||
|
||||
await t.test('should claim price impact rebates for valid account with claimable fees', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await claimGmxPriceImpactImpl(sdk);
|
||||
|
||||
console.log('Claim price impact result:', result);
|
||||
|
||||
// Should return a success indicator
|
||||
assert.ok(typeof result === 'string', 'Result should be a string');
|
||||
assert.equal(result, 'price_impact_claimed', 'Should return success indicator');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
|
||||
// Should be a meaningful error message
|
||||
assert.ok(
|
||||
error.message.includes('No price impact fees available to claim') ||
|
||||
error.message.includes('Failed to claim price impact rebates') ||
|
||||
error.message.includes('Error claiming price impact rebates'),
|
||||
'Error message should be meaningful'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should handle SDK client creation for claim', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// Validate SDK properties
|
||||
assert.ok(typeof sdk === 'object', 'SDK should be an object');
|
||||
assert.ok(sdk.account === testAccount, 'SDK account should match test account');
|
||||
assert.ok(typeof sdk.chainId === 'number', 'Chain ID should be a number');
|
||||
|
||||
console.log('SDK validation passed for claim');
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should automatically fetch claimable fees before claiming', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// The method should now automatically fetch claimable fees using GraphQL
|
||||
// This test verifies that the method integrates with getGmxPriceImpactRebatesImpl
|
||||
const result = await claimGmxPriceImpactImpl(sdk);
|
||||
|
||||
console.log('Auto-fetch and claim result:', result);
|
||||
|
||||
// If successful, should return the success indicator
|
||||
assert.equal(result, 'price_impact_claimed', 'Should return success indicator');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
|
||||
// Should handle the case where no claimable fees are found
|
||||
if (error.message.includes('No price impact fees available to claim')) {
|
||||
console.log('No claimable fees found - this is expected for test account');
|
||||
assert.ok(true, 'Correctly handled no claimable fees case');
|
||||
} else {
|
||||
assert.ok(
|
||||
error.message.includes('Failed to claim price impact rebates') ||
|
||||
error.message.includes('Error claiming price impact rebates'),
|
||||
'Should be a meaningful claim error'
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should handle chain ID validation for claim', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// Should only work for Arbitrum (chainId 42161)
|
||||
assert.equal(sdk.chainId, 42161, 'Should be using Arbitrum chain ID');
|
||||
|
||||
console.log('Chain ID validation passed for claim');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should validate contract addresses for claim', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// The method should validate that proper contract addresses are available
|
||||
// This tests the ExchangeRouter contract address retrieval
|
||||
await claimGmxPriceImpactImpl(sdk);
|
||||
|
||||
console.log('Contract validation passed');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
|
||||
// Validate error messages are meaningful
|
||||
assert.ok(
|
||||
error.message.includes('No price impact fees available to claim') ||
|
||||
error.message.includes('Failed to claim price impact rebates') ||
|
||||
error.message.includes('Unsupported chain ID') ||
|
||||
error.message.includes('Error claiming price impact rebates'),
|
||||
'Should provide meaningful error messages'
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,92 +0,0 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import {claimGmxUiFeesImpl, getClientForAddress} from '../../src/plugins/custom/gmx.js';
|
||||
|
||||
test('GMX Claim UI Fees Implementation', async (t) => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f';
|
||||
|
||||
t.test('should claim UI fees for valid account', async () => {
|
||||
try {
|
||||
// Get GMX SDK client for the test account
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// Call the implementation function directly
|
||||
const result = await claimGmxUiFeesImpl(sdk);
|
||||
|
||||
// Validate response
|
||||
assert.ok(typeof result === 'string', 'Result should be a string');
|
||||
assert.strictEqual(result, 'ui_fees_claimed', 'Should return success indicator');
|
||||
|
||||
console.log('UI fees claim result:', result);
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
// In test environment, this will likely fail due to no claimable fees or network issues
|
||||
// This is expected behavior in a test environment
|
||||
}
|
||||
});
|
||||
|
||||
t.test('should handle SDK initialization for different account', async () => {
|
||||
try {
|
||||
const differentAccount = '0x1234567890123456789012345678901234567890';
|
||||
|
||||
// Get GMX SDK client for a different account
|
||||
const sdk = await getClientForAddress(differentAccount);
|
||||
|
||||
// Verify SDK was created with correct account
|
||||
assert.strictEqual(sdk.account.toLowerCase(), differentAccount.toLowerCase(), 'SDK should be initialized with correct account');
|
||||
|
||||
// Call the implementation function
|
||||
const result = await claimGmxUiFeesImpl(sdk);
|
||||
|
||||
assert.ok(typeof result === 'string', 'Result should be a string');
|
||||
console.log('Different account claim result:', result);
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
t.test('should handle errors gracefully', async () => {
|
||||
try {
|
||||
// Test with invalid/empty account to see error handling
|
||||
const invalidAccount = '0x0000000000000000000000000000000000000000';
|
||||
const sdk = await getClientForAddress(invalidAccount);
|
||||
|
||||
await claimGmxUiFeesImpl(sdk);
|
||||
|
||||
// If we reach here without error, that's also valid
|
||||
console.log('Invalid account test passed without error');
|
||||
|
||||
} catch (error) {
|
||||
// Expected to fail with invalid account
|
||||
console.log('Error handling test - caught expected error:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
assert.ok(error.message.includes('Failed to claim UI fees') ||
|
||||
error.message.includes('No markets') ||
|
||||
error.message.includes('network') ||
|
||||
error.message.includes('RPC'), 'Should have meaningful error message');
|
||||
}
|
||||
});
|
||||
|
||||
t.test('should validate SDK client creation', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// Validate SDK properties
|
||||
assert.ok(sdk, 'SDK should be created');
|
||||
assert.ok(sdk.account, 'SDK should have account property');
|
||||
assert.ok(sdk.chainId, 'SDK should have chainId property');
|
||||
assert.strictEqual(sdk.account.toLowerCase(), testAccount.toLowerCase(), 'SDK account should match input');
|
||||
|
||||
console.log('SDK validation passed for account:', sdk.account);
|
||||
console.log('SDK chainId:', sdk.chainId);
|
||||
|
||||
} catch (error) {
|
||||
console.warn('SDK creation error:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,16 +1,16 @@
|
||||
import {test} from 'node:test'
|
||||
import assert from 'node:assert'
|
||||
import {closeGmxPositionImpl, getClientForAddress} from '../../src/plugins/custom/gmx'
|
||||
import {Ticker, TradeDirection} from '../../src/generated/ManagingApiTypes'
|
||||
import {TradeDirection} from '../../src/generated/ManagingApiTypes'
|
||||
|
||||
test('GMX Position Closing', async (t) => {
|
||||
await t.test('should close a long position for BTC', async () => {
|
||||
const sdk = await getClientForAddress('0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f')
|
||||
const sdk = await getClientForAddress('0x932167388dD9aad41149b3cA23eBD489E2E2DD78')
|
||||
|
||||
const result = await closeGmxPositionImpl(
|
||||
sdk,
|
||||
Ticker.SOL,
|
||||
TradeDirection.Long
|
||||
'GMX',
|
||||
TradeDirection.Short
|
||||
)
|
||||
console.log('Position closing result:', result)
|
||||
assert.ok(result, 'Position closing result should be defined')
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import {getClaimableFundingFeesImpl, getClientForAddress} from '../../src/plugins/custom/gmx.js';
|
||||
|
||||
test('GMX Get Claimable Funding Fees', async (t) => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f';
|
||||
|
||||
await t.test('should get claimable funding fees for valid account', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await getClaimableFundingFeesImpl(sdk);
|
||||
|
||||
console.log('Claimable funding fees result:', result);
|
||||
assert.ok(typeof result === 'object', 'Result should be an object');
|
||||
|
||||
// Check that each market entry has the expected structure
|
||||
Object.values(result).forEach(marketData => {
|
||||
assert.ok(typeof marketData.claimableFundingAmountLong === 'number', 'Long amount should be a number');
|
||||
assert.ok(typeof marketData.claimableFundingAmountShort === 'number', 'Short amount should be a number');
|
||||
assert.ok(marketData.claimableFundingAmountLong >= 0, 'Long amount should be non-negative');
|
||||
assert.ok(marketData.claimableFundingAmountShort >= 0, 'Short amount should be non-negative');
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
// In test environment, this may fail due to network issues or missing data
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,47 +0,0 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import {getClaimableUiFeesImpl, getClientForAddress} from '../../src/plugins/custom/gmx.js';
|
||||
|
||||
test('GMX Get Claimable UI Fees', async (t) => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f';
|
||||
|
||||
await t.test('should get claimable UI fees for valid account', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await getClaimableUiFeesImpl(sdk);
|
||||
|
||||
// Log total claimable amounts
|
||||
let totalFees = 0;
|
||||
let marketsWithFees = 0;
|
||||
|
||||
Object.entries(result).forEach(([marketAddress, marketData]) => {
|
||||
const amount = marketData.claimableUiFeeAmount;
|
||||
|
||||
totalFees += amount;
|
||||
|
||||
if (amount > 0) {
|
||||
marketsWithFees++;
|
||||
console.log(`Market ${marketAddress}:`);
|
||||
console.log(` Claimable UI fee amount: ${amount}`);
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`\nSummary for account ${testAccount}:`);
|
||||
console.log(`Total UI fees claimable: ${totalFees}`);
|
||||
console.log(`Markets with claimable fees: ${marketsWithFees}`);
|
||||
console.log(`Total markets checked: ${Object.keys(result).length}`);
|
||||
|
||||
assert.ok(typeof result === 'object', 'Result should be an object');
|
||||
|
||||
// Check that each market entry has the expected structure
|
||||
Object.values(result).forEach(marketData => {
|
||||
assert.ok(typeof marketData.claimableUiFeeAmount === 'number', 'UI fee amount should be a number');
|
||||
assert.ok(marketData.claimableUiFeeAmount >= 0, 'UI fee amount should be non-negative');
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
// In test environment, this may fail due to network issues or missing data
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,158 +0,0 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import {getClientForAddress, getGmxPriceImpactRebatesImpl} from '../../src/plugins/custom/gmx.js';
|
||||
|
||||
test('GMX Get Price Impact Rebates', async (t) => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f';
|
||||
|
||||
await t.test('should get price impact rebates for valid account', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await getGmxPriceImpactRebatesImpl(sdk);
|
||||
|
||||
console.log('Price impact rebates result:', result);
|
||||
|
||||
// Validate the structure
|
||||
assert.ok(typeof result === 'object', 'Result should be an object');
|
||||
assert.ok(Array.isArray(result.accruedPositionPriceImpactFees), 'accruedPositionPriceImpactFees should be an array');
|
||||
assert.ok(Array.isArray(result.claimablePositionPriceImpactFees), 'claimablePositionPriceImpactFees should be an array');
|
||||
|
||||
// Validate accrued fees structure (if any exist)
|
||||
result.accruedPositionPriceImpactFees.forEach(fee => {
|
||||
assert.ok(typeof fee.factor === 'bigint', 'factor should be bigint');
|
||||
assert.ok(typeof fee.value === 'bigint', 'value should be bigint');
|
||||
assert.ok(typeof fee.valueByFactor === 'bigint', 'valueByFactor should be bigint');
|
||||
assert.ok(typeof fee.timeKey === 'number', 'timeKey should be number');
|
||||
assert.ok(typeof fee.marketAddress === 'string', 'marketAddress should be string');
|
||||
assert.ok(typeof fee.tokenAddress === 'string', 'tokenAddress should be string');
|
||||
assert.ok(typeof fee.id === 'string', 'id should be string');
|
||||
assert.equal(fee.factor, 0n, 'accrued fees should have factor of 0');
|
||||
});
|
||||
|
||||
// Validate claimable fees structure (if any exist)
|
||||
result.claimablePositionPriceImpactFees.forEach(fee => {
|
||||
assert.ok(typeof fee.factor === 'bigint', 'factor should be bigint');
|
||||
assert.ok(typeof fee.value === 'bigint', 'value should be bigint');
|
||||
assert.ok(typeof fee.valueByFactor === 'bigint', 'valueByFactor should be bigint');
|
||||
assert.ok(typeof fee.timeKey === 'number', 'timeKey should be number');
|
||||
assert.ok(typeof fee.marketAddress === 'string', 'marketAddress should be string');
|
||||
assert.ok(typeof fee.tokenAddress === 'string', 'tokenAddress should be string');
|
||||
assert.ok(typeof fee.id === 'string', 'id should be string');
|
||||
assert.ok(fee.factor > 0n, 'claimable fees should have factor > 0');
|
||||
});
|
||||
|
||||
console.log(`Found ${result.accruedPositionPriceImpactFees.length} accrued fees`);
|
||||
console.log(`Found ${result.claimablePositionPriceImpactFees.length} claimable fees`);
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should handle SDK client creation for rebates', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// Validate SDK properties
|
||||
assert.ok(typeof sdk === 'object', 'SDK should be an object');
|
||||
assert.ok(sdk.account === testAccount, 'SDK account should match test account');
|
||||
assert.ok(typeof sdk.chainId === 'number', 'Chain ID should be a number');
|
||||
|
||||
console.log('SDK validation passed for rebates');
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should query GraphQL subgraph successfully', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await getGmxPriceImpactRebatesImpl(sdk);
|
||||
|
||||
// The result should be from real GraphQL query, not mock data
|
||||
console.log('Real GraphQL query result:', {
|
||||
accruedCount: result.accruedPositionPriceImpactFees.length,
|
||||
claimableCount: result.claimablePositionPriceImpactFees.length
|
||||
});
|
||||
|
||||
// Test that the data structure is valid regardless of content
|
||||
assert.ok(typeof result === 'object', 'Result should be an object');
|
||||
assert.ok('accruedPositionPriceImpactFees' in result, 'Should have accruedPositionPriceImpactFees');
|
||||
assert.ok('claimablePositionPriceImpactFees' in result, 'Should have claimablePositionPriceImpactFees');
|
||||
|
||||
// All returned fees should have valid valueByFactor calculations
|
||||
[...result.accruedPositionPriceImpactFees, ...result.claimablePositionPriceImpactFees].forEach(fee => {
|
||||
// Validate valueByFactor calculation
|
||||
const expectedValueByFactor = (fee.value * fee.factor) / (BigInt(10) ** BigInt(30));
|
||||
assert.equal(fee.valueByFactor, expectedValueByFactor, 'valueByFactor should be calculated correctly');
|
||||
|
||||
// Should not have items where factor > 0 but valueByFactor = 0 (these should be filtered out)
|
||||
if (fee.factor > 0n) {
|
||||
assert.ok(fee.valueByFactor > 0n, 'Claimable fees with factor > 0 should have valueByFactor > 0');
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should handle chain ID validation', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
|
||||
// Should only work for Arbitrum (chainId 42161)
|
||||
assert.equal(sdk.chainId, 42161, 'Should be using Arbitrum chain ID');
|
||||
|
||||
console.log('Chain ID validation passed');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should validate address formatting', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await getGmxPriceImpactRebatesImpl(sdk);
|
||||
|
||||
// All addresses should be lowercase and properly formatted
|
||||
[...result.accruedPositionPriceImpactFees, ...result.claimablePositionPriceImpactFees].forEach(fee => {
|
||||
assert.equal(fee.marketAddress, fee.marketAddress.toLowerCase(), 'Market address should be lowercase');
|
||||
assert.equal(fee.tokenAddress, fee.tokenAddress.toLowerCase(), 'Token address should be lowercase');
|
||||
assert.ok(fee.marketAddress.startsWith('0x'), 'Market address should start with 0x');
|
||||
assert.ok(fee.tokenAddress.startsWith('0x'), 'Token address should start with 0x');
|
||||
assert.equal(fee.marketAddress.length, 42, 'Market address should be 42 characters');
|
||||
assert.equal(fee.tokenAddress.length, 42, 'Token address should be 42 characters');
|
||||
});
|
||||
|
||||
console.log('Address formatting validation passed');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
|
||||
await t.test('should handle empty results gracefully', async () => {
|
||||
try {
|
||||
const sdk = await getClientForAddress(testAccount);
|
||||
const result = await getGmxPriceImpactRebatesImpl(sdk);
|
||||
|
||||
// Even if arrays are empty, structure should be valid
|
||||
assert.ok(typeof result === 'object', 'Result should be an object');
|
||||
assert.ok('accruedPositionPriceImpactFees' in result, 'Should have accruedPositionPriceImpactFees property');
|
||||
assert.ok('claimablePositionPriceImpactFees' in result, 'Should have claimablePositionPriceImpactFees property');
|
||||
|
||||
console.log('Empty results handling validated');
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Expected error in test environment:', error.message);
|
||||
assert.ok(error instanceof Error, 'Should throw an Error instance');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
import {test} from 'node:test'
|
||||
import assert from 'node:assert'
|
||||
import {getClientForAddress, getGmxRebateStatsImpl} from '../../src/plugins/custom/gmx.ts'
|
||||
|
||||
test('GMX get rebate stats', async (t) => {
|
||||
await t.test('should get rebate stats for account', async () => {
|
||||
const testAccount = '0xbBA4eaA534cbD0EcAed5E2fD6036Aec2E7eE309f'
|
||||
const sdk = await getClientForAddress(testAccount)
|
||||
|
||||
const result = await getGmxRebateStatsImpl(sdk)
|
||||
|
||||
console.log('Rebate stats result:', result)
|
||||
assert.ok(result, 'Rebate stats result should be defined')
|
||||
|
||||
// Check that the result has the expected structure
|
||||
assert.ok(typeof result.totalRebateUsd === 'number', 'totalRebateUsd should be a number')
|
||||
assert.ok(typeof result.discountUsd === 'number', 'discountUsd should be a number')
|
||||
assert.ok(typeof result.volume === 'number', 'volume should be a number')
|
||||
assert.ok(typeof result.tier === 'number', 'tier should be a number')
|
||||
assert.ok(typeof result.rebateFactor === 'number', 'rebateFactor should be a number')
|
||||
assert.ok(typeof result.discountFactor === 'number', 'discountFactor should be a number')
|
||||
|
||||
// All values should be non-negative
|
||||
assert.ok(result.totalRebateUsd >= 0, 'totalRebateUsd should be non-negative')
|
||||
assert.ok(result.discountUsd >= 0, 'discountUsd should be non-negative')
|
||||
assert.ok(result.volume >= 0, 'volume should be non-negative')
|
||||
assert.ok(result.tier >= 0, 'tier should be non-negative')
|
||||
assert.ok(result.rebateFactor >= 0, 'rebateFactor should be non-negative')
|
||||
assert.ok(result.discountFactor >= 0, 'discountFactor should be non-negative')
|
||||
})
|
||||
})
|
||||
@@ -1,32 +0,0 @@
|
||||
import {before, describe, it} from 'node:test'
|
||||
import assert from 'node:assert'
|
||||
import {getClientForAddress, swapGmxTokensImpl} from '../../src/plugins/custom/gmx.js'
|
||||
import {Ticker} from '../../src/generated/ManagingApiTypes'
|
||||
|
||||
describe('swap tokens implementation', () => {
|
||||
let sdk: any
|
||||
|
||||
before(async () => {
|
||||
// Initialize the SDK with a test account
|
||||
const testAccount = '0xbba4eaa534cbd0ecaed5e2fd6036aec2e7ee309f'
|
||||
sdk = await getClientForAddress(testAccount)
|
||||
})
|
||||
|
||||
it('should swap USDC to ETH successfully', async () => {
|
||||
try {
|
||||
const result = await swapGmxTokensImpl(
|
||||
sdk,
|
||||
Ticker.GMX, // fromTicker
|
||||
Ticker.USDC, // toTicker
|
||||
2.06 // amount
|
||||
)
|
||||
|
||||
assert.strictEqual(typeof result, 'string')
|
||||
assert.strictEqual(result, 'swap_order_created')
|
||||
} catch (error) {
|
||||
// Test that the error is related to actual execution rather than parameter validation
|
||||
assert.ok(error instanceof Error)
|
||||
console.log('Expected error during test execution:', error.message)
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user