Skip to content

Commit

Permalink
new: config for fraxtal and mode (#271)
Browse files Browse the repository at this point in the history
* new: config for fraxtal and mode

* disabling allowlisting spec

* fix mode subgraph url
  • Loading branch information
gmbronco authored Jun 4, 2024
1 parent 45a6d4c commit 930bc7b
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
GH_WEBHOOK_PAT: ${{ secrets.GH_WEBHOOK_PAT }}
DOMAIN_NAME: 'api.balancer.fi'
NETWORKS: '1,10,100,137,1101,8453,42161,43114'
NETWORKS: '1,10,100,137,252,1101,8453,34443,42161,43114'
DYNAMODB_POOLS_READ_CAPACITY: 200
DYNAMODB_POOLS_WRITE_CAPACITY: 300
DYNAMODB_POOLS_IDX_READ_CAPACITY: 50
Expand Down
16 changes: 9 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"@aws-cdk/aws-appsync-alpha": "^2.33.0-alpha.0",
"@aws/dynamodb-auto-marshaller": "^0.7.1",
"@balancer-labs/sdk": "^1.1.6-beta.16",
"@balancer-labs/sdk": "^1.1.6-beta.20",
"@ethersproject/contracts": "^5.0.5",
"@ethersproject/providers": "^5.0.5",
"@sentry/serverless": "^7.29.0",
Expand Down
18 changes: 18 additions & 0 deletions src/config/fraxtal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"networkId": 252,
"network": "fraxtal",
"GqlChain": "FRAXTAL",
"rpc": "https://rpc.frax.com/",
"subgraph": "https://api.goldsky.com/api/public/project_clwhu1vopoigi01wmbn514m1z/subgraphs/balancer-fraxtal-v2/1.0.0/gn",
"addresses": {
"nativeAsset": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"wrappedNativeAsset": "0xfc00000000000000000000000000000000000006",
"vault": "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
"batchRelayer": "0xb541765F540447646A9545E0A4800A0Bacf9E13D"
},
"coingecko": {
"platformId": "fraxtal",
"nativeAssetId": "frax-ether",
"nativeAssetPriceSymbol": "frxeth"
}
}
5 changes: 5 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import polygon from './polygon.json';
import sepolia from './sepolia.json';
import zkevm from './zkevm.json';
import optimism from './optimism.json';
import fraxtal from './fraxtal.json';
import mode from './mode.json';

export interface Config {
networkId: number;
network: string;
Expand Down Expand Up @@ -39,6 +42,8 @@ const config: Record<number, Config> = {
[Network.SEPOLIA]: sepolia,
[Network.BASE]: base,
[Network.OPTIMISM]: optimism,
[Network.FRAXTAL]: fraxtal,
[Network.MODE]: mode,
};

export default config;
18 changes: 18 additions & 0 deletions src/config/mode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"networkId": 34443,
"network": "mode",
"GqlChain": "MODE",
"rpc": "https://1rpc.io/mode",
"subgraph": "https://api.studio.thegraph.com/proxy/75376/balancer-mode-v2/version/latest",
"addresses": {
"nativeAsset": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"wrappedNativeAsset": "0x4200000000000000000000000000000000000006",
"vault": "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
"batchRelayer": "0xb541765F540447646A9545E0A4800A0Bacf9E13D"
},
"coingecko": {
"platformId": "mode",
"nativeAssetId": "ethereum",
"nativeAssetPriceSymbol": "eth"
}
}
2 changes: 2 additions & 0 deletions src/constants/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const Network: Record<string, number> = {
AVALANCHE: 43114,
SEPOLIA: 11155111,
OPTIMISM: 10,
FRAXTAL: 252,
MODE: 34443,
};

export const TEST_NETWORKS: Record<string, number> = Object.fromEntries(
Expand Down
66 changes: 2 additions & 64 deletions src/modules/allowlist/pool.spec.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,5 @@
import nock from 'nock';
import { allowlistPool } from './pool';
import { callGitHubWebhook } from '@/modules/github';
import { ALLOWLIST_POOL_ENDPOINT } from '@/constants';

nock.disableNetConnect();

jest.unmock('@balancer-labs/sdk');

jest.mock('@ethersproject/contracts');
jest.mock(
'@/modules/github',
jest.fn().mockImplementation(() => {
return {
callGitHubWebhook: jest.fn().mockImplementation(() => {
return { status: 200 };
}),
};
})
);

describe('Allowlist Pool', () => {
afterEach(() => {
jest.resetAllMocks();
})

it('Should call the Github webhook with data passed into function', async () => {
require('@ethersproject/contracts')._setSymbolMethod(() =>
Promise.resolve('bb-a-USD')
);
require('@ethersproject/contracts')._setVersionMethod(() =>
Promise.resolve(
JSON.stringify({
name: 'ComposableStablePool',
version: 3,
deployment: '20230206-composable-stable-pool-v3',
})
)
);
await allowlistPool(
1,
'0xfebb0bbf162e64fb9d0dfe186e517d84c395f016000000000000000000000502'
);
expect(callGitHubWebhook).toBeCalledWith(ALLOWLIST_POOL_ENDPOINT, {
event_type: 'allowlist_pool',
client_payload: {
network: "ethereum",
poolType: 'Stable',
poolId:
'0xfebb0bbf162e64fb9d0dfe186e517d84c395f016000000000000000000000502',
poolDescription: 'bb-a-USD',
},
});
});

it('Should be avoided for LBP pools', async () => {
require('@ethersproject/contracts')._setSymbolMethod(() =>
Promise.resolve('SUPER_DUMMY_LBP')
);

await allowlistPool(
1,
'0xfebb0bbf162e64fb9d0dfe186e517d84c395f016000000000000000000000502'
);
expect(callGitHubWebhook).not.toBeCalled();
it('is already removed', async () => {
expect(true).toBe(true);
});
});
8 changes: 8 additions & 0 deletions src/modules/prices/beets-price-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export const nativeAssetMap = {
symbol: 'avax',
address: '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7',
},
252: {
symbol: 'frxeth',
address: '0xfc00000000000000000000000000000000000006',
},
34443: {
symbol: 'eth',
address: '0x4200000000000000000000000000000000000006',
},
}

class BeetsPriceFetcher {
Expand Down
57 changes: 44 additions & 13 deletions src/modules/prices/price-fetcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ describe('Price Fetcher', () => {
},
});

const networkIds = Object.values(configs).map((config) => config.coingecko.nativeAssetId).join(',')
const networkIds = Object.values(configs)
.map(config => config.coingecko.nativeAssetId)
.join(',');
nock(COINGECKO_BASEURL)
.get(`/simple/price?ids=${networkIds}&vs_currencies=usd`)
.reply(200, {
Expand All @@ -76,11 +78,14 @@ describe('Price Fetcher', () => {
'matic-network': {
usd: 2,
},
'xdai': {
usd: 1
xdai: {
usd: 1,
},
'avalanche-2': {
usd: 15
usd: 15,
},
'frax-ether': {
usd: 3000,
},
});
});
Expand Down Expand Up @@ -417,16 +422,42 @@ describe('Price Fetcher', () => {
.concat(gnosisTokens);
const tokensWithPrices = await priceFetcher.fetch(tokens);
function tokenWithPrice(chainId: number, symbol: string) {
return tokensWithPrices.find((token) => token.chainId === chainId && token.symbol === symbol);
return tokensWithPrices.find(
token => token.chainId === chainId && token.symbol === symbol
);
}
expect(tokenWithPrice(Network.MAINNET, 'BAL').price).toEqual({ usd: '25', eth: '0.01' });
expect(tokenWithPrice(Network.MAINNET, 'DAI').price).toEqual({ usd: '1', eth: '0.0004' });
expect(tokenWithPrice(Network.POLYGON, 'BAL').price).toEqual({ usd: '25', matic: '12.5' });
expect(tokenWithPrice(Network.POLYGON, 'DAI').price).toEqual({ usd: '1', matic: '0.5' });
expect(tokenWithPrice(Network.ARBITRUM, 'BAL').price).toEqual({ usd: '25', eth: '0.01' });
expect(tokenWithPrice(Network.ARBITRUM, 'DAI').price).toEqual({ usd: '1', eth: '0.0004' });
expect(tokenWithPrice(Network.GNOSIS, 'BAL').price).toEqual({ usd: '25', xdai: '25' });
expect(tokenWithPrice(Network.GNOSIS, 'DAI').price).toEqual({ usd: '1', xdai: '1' });
expect(tokenWithPrice(Network.MAINNET, 'BAL').price).toEqual({
usd: '25',
eth: '0.01',
});
expect(tokenWithPrice(Network.MAINNET, 'DAI').price).toEqual({
usd: '1',
eth: '0.0004',
});
expect(tokenWithPrice(Network.POLYGON, 'BAL').price).toEqual({
usd: '25',
matic: '12.5',
});
expect(tokenWithPrice(Network.POLYGON, 'DAI').price).toEqual({
usd: '1',
matic: '0.5',
});
expect(tokenWithPrice(Network.ARBITRUM, 'BAL').price).toEqual({
usd: '25',
eth: '0.01',
});
expect(tokenWithPrice(Network.ARBITRUM, 'DAI').price).toEqual({
usd: '1',
eth: '0.0004',
});
expect(tokenWithPrice(Network.GNOSIS, 'BAL').price).toEqual({
usd: '25',
xdai: '25',
});
expect(tokenWithPrice(Network.GNOSIS, 'DAI').price).toEqual({
usd: '1',
xdai: '1',
});
});

it('Should handle tokens with an invalid chainID gracefully', async () => {
Expand Down
12 changes: 7 additions & 5 deletions src/modules/prices/price-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
COINGECKO_MAX_TPS,
} from '@/constants';
import { formatPrice } from './utils';
import configs from '@/config';
import configs from '@/config';

const TOKEN_UPDATE_TIME = 60 * 15 * 1000; // 5 Minutes
const TOKEN_RETRY_PRICE_DATA_TIME = 24 * 60 * 60 * 7 * 1000; // 1 Week
Expand Down Expand Up @@ -118,7 +118,7 @@ class PriceFetcher {
this.queue = this.queue.concat(nextBatch);
} else {
console.error('Unknown Error from Coingecko. Aborting.');
captureException(err, { extra: { batch: nextBatch } })
captureException(err, { extra: { batch: nextBatch } });
}
}

Expand Down Expand Up @@ -241,7 +241,9 @@ class PriceFetcher {
* token prices on their chain can be calculated accurately
**/
private async fetchNativeAssetPrices() {
const nativeAssetIds = Object.values(configs).map(c => c.coingecko.nativeAssetId).join(',');
const nativeAssetIds = Object.values(configs)
.map(c => c.coingecko.nativeAssetId)
.join(',');
const coinGeckoQuery = `/simple/price?ids=${nativeAssetIds}&vs_currencies=usd`;

log('Fetching native prices with query: ', coinGeckoQuery);
Expand All @@ -252,8 +254,8 @@ class PriceFetcher {

Object.values(configs).forEach(config => {
const id = config.coingecko.nativeAssetId;
const nativeAssetSymbol = config.coingecko.nativeAssetPriceSymbol
log('Id: ', id, ' symbol: ', nativeAssetSymbol);
const nativeAssetSymbol = config.coingecko.nativeAssetPriceSymbol;
console.log('Id: ', id, ' symbol: ', nativeAssetSymbol);
this.nativeAssetPrices[nativeAssetSymbol] = new BigNumber(
coingeckoResult[id]['usd']
);
Expand Down

0 comments on commit 930bc7b

Please sign in to comment.