Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include method to execute tx across parifi relayer #35

Merged
merged 7 commits into from
Mar 27, 2024
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ PYTH_SERVICE_USERNAME =
PYTH_SERVICE_PASSWORD =
GELATO_KEY =
SUBGRAPH_ENDPOINT =
PARIFI_RELAYER_JWT_TOKEN=
2,197 changes: 1,046 additions & 1,151 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@parifi/sdk",
"version": "0.1.5",
"version": "0.1.8",
"description": "Parifi SDK with common utility functions",
"files": [
"dist",
Expand Down Expand Up @@ -46,7 +46,7 @@
},
"dependencies": {
"@gelatonetwork/relay-sdk": "^5.5.5",
"@parifi/references": "^1.1.0-dev",
"@parifi/references": "1.1.0-dev",
"axios": "^1.6.7",
"decimal.js": "^10.4.3",
"dotenv": "^16.4.1",
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Subgraph } from './subgraph';
import { PythConfig, RelayerConfig, RpcConfig, SubgraphConfig } from './interfaces/classConfigs';
import { Core } from './core';
import { Gelato } from './gelato';
import { relayerRepository } from './interfaces/repositories/relayer';
import { ParifiRelayer } from './relayers/parifi';

export * from './common';
export * from './core';
Expand All @@ -16,6 +18,9 @@ export class ParifiSdk {
pyth: Pyth;
core: Core;
gelato: Gelato;
relayer: {
parifi: relayerRepository;
};

constructor(
rpcConfig: RpcConfig,
Expand All @@ -27,6 +32,9 @@ export class ParifiSdk {
this.pyth = new Pyth(pythConfig);
this.core = new Core(rpcConfig, subgraphConfig, relayerConfig, pythConfig);
this.gelato = new Gelato(relayerConfig['gelatoConfig'], rpcConfig);
this.relayer = {
parifi: new ParifiRelayer(relayerConfig['parifiRealyerConfig'], rpcConfig.chainId),
};
}

async init() {
Expand Down
13 changes: 13 additions & 0 deletions src/interfaces/repositories/relayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { TransactionStatusResponse } from '@gelatonetwork/relay-sdk';

export type RelayerTransaction = {
to: string;
data: string;
value: string | number;
customTxId?: string;
};

export interface relayerRepository {
executeTx: (tx: RelayerTransaction) => Promise<string>;
checkStatus: (identifier: string) => Promise<TransactionStatusResponse | undefined>;
}
32 changes: 32 additions & 0 deletions src/relayers/parifi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { RelayerConfig } from '../../interfaces';
import { RelayerTransaction, relayerRepository } from '../../interfaces/repositories/relayer';

export class ParifiRelayer implements relayerRepository {
private token: string;
public url: string;
public chainId: number;

constructor(relayerConfig: RelayerConfig['parifiRealyerConfig'], chainId: number) {
this.token = relayerConfig?.jwtToken ?? '';
this.url = relayerConfig?.relayerEndpoint ?? 'https://balancer.parifi.org';
this.chainId = chainId;
}

async executeTx({ customTxId, ...tx }: RelayerTransaction) {
const response = await fetch(`${this.url}/send`, {
headers: {
Authorization: `Bearer ${this.token}`,
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify({ tx, chainId: this.chainId.toString(), customTxId }),
});
const data = await response.json();

return (customTxId ?? data.txId) as string;
}

async checkStatus(_hash: string) {
return undefined;
}
}
1 change: 1 addition & 0 deletions src/relayers/parifi/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const executeTxUsingParifi = ({}) => {};
3 changes: 1 addition & 2 deletions src/subgraph/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { Chain } from '@parifi/references';
export const publicSubgraphEndpoints: { [key in Chain]: string } = {
[Chain.ARBITRUM_SEPOLIA]: 'https://api.thegraph.com/subgraphs/name/parifi/parifi-sepolia',
[Chain.ARBITRUM_MAINNET]: 'https://subgraph.satsuma-prod.com/ac10c1d41dcb/parifis-team--3804602/parifi-arbitrum/api',

};

export const getPublicSubgraphEndpoint = (chainId: Chain) => {
return publicSubgraphEndpoints[chainId];
};
};
4 changes: 4 additions & 0 deletions src/subgraph/vaults/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import Decimal from 'decimal.js';
import { getLatestPricesFromPyth, normalizePythPriceForParifi } from '../../pyth/pyth';
import { AxiosInstance } from 'axios';

// const matchChain: Record<SupportedChain, Chain> = {
// [SupportedChain.ARBITRUM_SEPOLIA]: arbitrumSepolia,
// };

// Get all vaults from subgraph
export const getAllVaults = async (subgraphEndpoint: string): Promise<Vault[]> => {
try {
Expand Down
41 changes: 41 additions & 0 deletions test/core/relayer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Chain } from '@parifi/references';
import { ParifiSdk, PythConfig, RelayerConfig, RelayerI, RpcConfig, SubgraphConfig } from '../../src';

const chain = Chain.ARBITRUM_SEPOLIA;
const rpcConfig: RpcConfig = {
chainId: chain,
};

const pythConfig: PythConfig = {
pythEndpoint: process.env.PYTH_SERVICE_ENDPOINT,
username: process.env.PYTH_SERVICE_USERNAME,
password: process.env.PYTH_SERVICE_PASSWORD,
isStable: true,
};

const parifiConfig: RelayerI = {
jwtToken: process.env.PARIFI_RELAYER_JWT_TOKEN || '',
// relayerEndpoint: 'http://localhost:3001',
};

const relayerConfig: RelayerConfig = {
parifiRealyerConfig: parifiConfig,
};

const subgraphConfig: SubgraphConfig = {
subgraphEndpoint: 'https://api.studio.thegraph.com/query/68480/parifi-arb-sepolia-test-dev/v0.0.6',
};

const parifiSdk = new ParifiSdk(rpcConfig, subgraphConfig, relayerConfig, pythConfig);

describe('ParifiSdk parifi relayer', () => {
it('should return txId', async () => {
const txId = await parifiSdk.relayer.parifi.executeTx({
to: '0x15758472aF37950028ad27e4a7F99e65A4A997Cc',
data: '0x095ea7b30000000000000000000000003232f21a6e08312654270c78a773f00dd61d60f500000000000000000000000000000000000000000000000000000000000003e8',
value: '0',
});
console.log('=== txId', txId);
expect(txId).toBeTruthy();
});
});
Loading