Skip to content

Commit

Permalink
Merge pull request #34 from rabbitholegg/gmx_stargate_hotfix
Browse files Browse the repository at this point in the history
Fix(gmx&stargate): chain id return and fetch->axios
  • Loading branch information
Quazia authored Sep 22, 2023
2 parents 6eb099c + 6141bb2 commit 01d06e7
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 75 deletions.
6 changes: 6 additions & 0 deletions .changeset/neat-teachers-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rabbitholegg/questdk-plugin-stargate": patch
"@rabbitholegg/questdk-plugin-gmx": patch
---

Switch from fetch to axios and return correct chain IDs in stargate
20 changes: 10 additions & 10 deletions packages/gmx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rabbitholegg/questdk-plugin-gmx",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.3",
"type": "module",
"exports": {
"require": "./dist/cjs/index.js",
Expand Down Expand Up @@ -34,18 +34,18 @@
"types": "./dist/types/index.d.ts",
"typings": "./dist/types/index.d.ts",
"devDependencies": {
"@types/node": "^20.4.5",
"@vitest/coverage-v8": "^0.33.0",
"rimraf": "^5.0.1",
"rome": "^12.1.3",
"ts-node": "^10.9.1",
"@types/node": "20.4.5",
"@vitest/coverage-v8": "0.33.0",
"rimraf": "5.0.1",
"rome": "12.1.3",
"ts-node": "10.9.1",
"tsconfig": "workspace:*",
"typescript": "^5.1.6",
"vitest": "^0.33.0"
"typescript": "5.1.6",
"vitest": "0.33.0"
},
"dependencies": {
"@rabbitholegg/questdk": "1.0.1-alpha.10",
"node-fetch": "^3.3.2",
"viem": "^1.2.15"
"axios": "1.5.0",
"viem": "1.2.15"
}
}
7 changes: 6 additions & 1 deletion packages/gmx/src/GMX.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { GreaterThanOrEqual, apply } from '@rabbitholegg/questdk/filter'
import { describe, expect, test } from 'vitest'
import { GMX_SWAPV1_ABI } from './abi.js'
import { swap } from './GMX.js'
import { getSupportedTokenAddresses, swap } from './GMX.js'
import { ARB_ONE_CHAIN_ID } from './chain-ids.js'
import { SWAP_ETH, SWAP_ETH_V2 } from './test-transactions.js'
import { parseEther } from 'viem'
import {
DEFAULT_TOKEN_LIST_URL,
GMX_ROUTERV1_ADDRESS,
GMX_ROUTERV2_ADDRESS,
} from './contract-addresses.js'
Expand Down Expand Up @@ -69,5 +70,9 @@ describe('Given the gmx plugin', () => {
})
expect(apply(transaction, filter)).to.be.true
})
test('should return the correct list of tokens', async () => {
const tokens = await getSupportedTokenAddresses(ARB_ONE_CHAIN_ID)
expect(tokens).to.deep.equal(DEFAULT_TOKEN_LIST_URL)
})
})
})
8 changes: 4 additions & 4 deletions packages/gmx/src/GMX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DEFAULT_TOKEN_LIST_URL,
GMX_ROUTERV1_ADDRESS,
} from './contract-addresses.js'
import fetch from 'node-fetch'
import axios from 'axios'
import { type Address } from 'viem'

enum OrderType {
Expand Down Expand Up @@ -84,12 +84,12 @@ export const swap = async (swap: SwapActionParams) => {
export const getSupportedTokenAddresses = async (_chainId: number) => {
try {
// Send a GET request to the specified URL using the fetch API
const response = await fetch('https://api.gmx.io/tokens')
const response = await axios.get('https://api.gmx.io/tokens')

// Check if the request was successful (status code 200)
if (response.ok) {
if (response.statusText === 'OK') {
// Parse the JSON response into a JavaScript object
const data = (await response.json()) as Array<{ data: any; id: string }>
const data = response.data as Array<{ data: any; id: string }>
return data.map((token) => token.id) as Address[]
} else {
console.error(`Request failed with status code: ${response.status}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/stargate/src/Stargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type Address } from 'viem'
import { STARGATE_BRIDGE_ABI } from './abi.js'
import {
ARBITRUM_CHAIN_ID,
CHAIN_ID_ARRAY,
NATIVE_CHAIN_ID_ARRAY,
ETH_CHAIN_ID,
LAYER_ONE_TO_LAYER_ZERO_CHAIN_ID,
POLYGON_CHAIN_ID,
Expand Down Expand Up @@ -77,5 +77,5 @@ export const getSupportedTokenAddresses = async (
}

export const getSupportedChainIds = async () => {
return CHAIN_ID_ARRAY as number[]
return NATIVE_CHAIN_ID_ARRAY as number[]
}
16 changes: 15 additions & 1 deletion packages/stargate/src/chain-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const LAYER_ONE_TO_LAYER_ZERO_CHAIN_ID: Record<number, number> = {
[BASE_CHAIN_ID]: BASE_LAYER_ZERO_CHAIN_ID,
} as const

export const CHAIN_ID_ARRAY = [
export const LAYER_ZERO_CHAIN_ID_ARRAY = [
ETH_LAYER_ZERO_CHAIN_ID,
BNB_LAYER_ZERO_CHAIN_ID,
AVALANCHE_LAYER_ZERO_CHAIN_ID,
Expand All @@ -63,3 +63,17 @@ export const CHAIN_ID_ARRAY = [
LINEA_LAYER_ZERO_CHAIN_ID,
BASE_LAYER_ZERO_CHAIN_ID,
]

export const NATIVE_CHAIN_ID_ARRAY = [
ETH_CHAIN_ID,
BNB_CHAIN_ID,
AVALANCHE_CHAIN_ID,
POLYGON_CHAIN_ID,
ARBITRUM_CHAIN_ID,
OPTIMISM_CHAIN_ID,
FANTOM_CHAIN_ID,
METIS_CHAIN_ID,
KAVA_CHAIN_ID,
LINEA_CHAIN_ID,
BASE_CHAIN_ID,
]
85 changes: 28 additions & 57 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 01d06e7

Please sign in to comment.