Skip to content

Commit

Permalink
fix tests and clean repo
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeNervoXS committed Sep 14, 2023
1 parent a7ab401 commit a8a3210
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 90 deletions.
6 changes: 3 additions & 3 deletions scripts/fetch-event-blocknumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Network } from '../src/constants';
import { Address } from '../src/types';
import { generateConfig } from '../src/config';
// TODO: Import correct ABI
import ABI from '../src/abi/chainlink.json';
import ABI from '../src/abi/angle-transmuter/Transmuter.json';

// This is a helper script to fetch blockNumbers where a certain
// event was released by a certain contract
Expand Down Expand Up @@ -41,8 +41,8 @@ async function getBlockNumbersForEvents(

// TODO: Set your values here
const network = Network.MAINNET;
const eventNames = ['AnswerUpdated'];
const address = '0x83Ec02059F686E747392A22ddfED7833bA0d7cE3';
const eventNames = ['WhitelistStatusToggled'];
const address = '0x00253582b2a3FE112feEC532221d9708c64cEFAb';
const provider = new StaticJsonRpcProvider(
generateConfig(network).privateHttpProvider,
network,
Expand Down
39 changes: 18 additions & 21 deletions src/dex/angle-transmuter/angle-transmuter-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ function testForNetwork(
const holders = Holders[network];
const nativeTokenSymbol = NativeTokenSymbols[network];

// TODO: Add any direct swap contractMethod name if it exists
const sideToContractMethods = new Map([
[SwapSide.SELL, [ContractMethod.simpleSwap]],
// TODO: If buy is not supported remove the buy contract methods
[SwapSide.BUY, [ContractMethod.simpleBuy]],
]);

Expand Down Expand Up @@ -106,25 +104,24 @@ describe('AngleTransmuter E2E', () => {
describe('Mainnet', () => {
const network = Network.MAINNET;

// describe('EUROC', () => {

// const tokenASymbol: string = 'EUROC';
// const tokenBSymbol: string = 'agEUR';

// const tokenAAmount: string = '1000000';
// const tokenBAmount: string = '1000000000000000000';
// const nativeTokenAmount = '1000000000000000000';

// testForNetwork(
// network,
// dexKey,
// tokenASymbol,
// tokenBSymbol,
// tokenAAmount,
// tokenBAmount,
// nativeTokenAmount,
// );
// });
describe('EUROC', () => {
const tokenASymbol: string = 'EUROC';
const tokenBSymbol: string = 'agEUR';

const tokenAAmount: string = '1000000';
const tokenBAmount: string = '1000000000000000000';
const nativeTokenAmount = '1000000000000000000';

testForNetwork(
network,
dexKey,
tokenASymbol,
tokenBSymbol,
tokenAAmount,
tokenBAmount,
nativeTokenAmount,
);
});
describe('BC3M', () => {
const tokenASymbol: string = 'bC3M';
const tokenBSymbol: string = 'agEUR';
Expand Down
8 changes: 5 additions & 3 deletions src/dex/angle-transmuter/angle-transmuter-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ async function fetchPoolState(
blockNumber: number,
poolAddress: string,
): Promise<DeepReadonly<PoolState>> {
// TODO: complete me!
return angleTransmuterPools.generateState(blockNumber);
}

Expand All @@ -66,14 +65,18 @@ describe('AngleTransmuter EventPool Mainnet', function () {

// poolAddress -> EventMappings
const eventsToTest: Record<Address, EventMappings> = {
// TODO: complete me!
//Transmuter Events
'0x00253582b2a3FE112feEC532221d9708c64cEFAb': {
FeesSet: [],
RedemptionCurveParamsSet: [],
OracleSet: [],
Swap: [18012837],
Redeemed: [],
ReservesAdjusted: [],
CollateralAdded: [],
CollateralRevoked: [],
CollateralWhitelistStatusUpdated: [],
WhitelistStatusToggled: [],
},
// Pyth Events
'0x4305FB66699C3B2702D4d05CF36551390A4c69C6': {
Expand Down Expand Up @@ -106,7 +109,6 @@ describe('AngleTransmuter EventPool Mainnet', function () {
network,
dexHelper,
logger,
/* TODO: Put here additional constructor arguments if needed */
{
agEUR: {
address: '0x1a7e4e63778B4f12a199C062f3eFdD288afCBce8',
Expand Down
20 changes: 5 additions & 15 deletions src/dex/angle-transmuter/angle-transmuter-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ function getReaderCalldata(
readerIface: Interface,
amounts: bigint[],
funcName: string,
// TODO: Put here additional arguments you need
tokenIn: Address,
tokenOut: Address,
) {
return amounts.map(amount => ({
target: exchangeAddress,
callData: readerIface.encodeFunctionData(funcName, [
// TODO: Put here additional arguments to encode them
amount,
tokenIn,
tokenOut,
Expand All @@ -56,7 +54,6 @@ function decodeReaderResult(
readerIface: Interface,
funcName: string,
) {
// TODO: Adapt this function for your needs
return results.map(result => {
const parsed = readerIface.decodeFunctionResult(funcName, result);
return BigInt(parsed[0]._hex);
Expand All @@ -72,11 +69,7 @@ async function checkOnChainPricing(
tokenIn: Address,
tokenOut: Address,
) {
const exchangeAddress = '0x00253582b2a3FE112feEC532221d9708c64cEFAb'; // TODO: Put here the real exchange address

// TODO: Replace dummy interface with the real one
// Normally you can get it from angleTransmuter.Iface or from eventPool.
// It depends on your implementation
const exchangeAddress = '0x00253582b2a3FE112feEC532221d9708c64cEFAb';
const readerIface = AngleTransmuterEventPool.angleTransmuterIface;

const readerCallData = getReaderCalldata(
Expand Down Expand Up @@ -106,7 +99,6 @@ async function checkOnChainPricing(
(expectedPrices[i] * 100001n) / 100000n,
);
}
// expect(prices).toEqual(expectedPrices);
}

async function testPricingOnNetwork(
Expand Down Expand Up @@ -178,10 +170,8 @@ describe('AngleTransmuter', function () {

const tokens = Tokens[network];

// TODO: Put here token Symbol to check against
// Don't forget to update relevant tokens in constant-e2e.ts
const srcTokenSymbol = 'agEUR';
const destTokenSymbol = 'bC3M';
const srcTokenSymbol = 'EUROC';
const destTokenSymbol = 'agEUR';

const amountsForSell = [
0n,
Expand Down Expand Up @@ -229,7 +219,7 @@ describe('AngleTransmuter', function () {
destTokenSymbol,
SwapSide.SELL,
amountsForSell,
'quoteIn', // TODO: Put here proper function name to check pricing
'quoteIn',
);
});

Expand All @@ -243,7 +233,7 @@ describe('AngleTransmuter', function () {
destTokenSymbol,
SwapSide.BUY,
amountsForBuy,
'quoteOut', // TODO: Put here proper function name to check pricing
'quoteOut',
);
});

Expand Down
15 changes: 4 additions & 11 deletions src/dex/angle-transmuter/angle-transmuter-pool.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Interface } from '@ethersproject/abi';
import { DeepReadonly } from 'ts-essentials';
import { lens } from '../../lens';
import { Address, Logger, Token } from '../../types';
import { Address, Logger } from '../../types';
import { ComposedEventSubscriber } from '../../composed-event-subscriber';
import { ChainLinkSubscriber } from '../../lib/chainlink';
import { IDexHelper } from '../../dex-helper/idex-helper';
import {
ChainlinkConfig,
DecodedOracleConfig,
DexParams,
Oracle,
OracleFeed,
OracleQuoteType,
OracleReadType,
Expand All @@ -19,7 +18,6 @@ import {
TransmuterState,
} from './types';
import TransmuterABI from '../../abi/angle-transmuter/Transmuter.json';
import { CBETH, RETH, SFRXETH, STETH } from './constants';
import { Contract } from 'web3-eth-contract';
import { TransmuterSubscriber } from './transmuter';
import { PythSubscriber } from './pyth';
Expand Down Expand Up @@ -121,10 +119,6 @@ export class AngleTransmuterEventPool extends ComposedEventSubscriber<PoolState>
pythListener,
],
{
// TODO: poolState is the state of event
// subscriber. This should be the minimum
// set of parameters required to compute
// pool prices. Complete me!
stablecoin: config.agEUR,
transmuter: {} as TransmuterState,
oracles: { chainlink: {}, pyth: {} },
Expand Down Expand Up @@ -156,11 +150,10 @@ export class AngleTransmuterEventPool extends ComposedEventSubscriber<PoolState>
_amounts: number[],
blockNumber: number,
): Promise<number[] | null> {
// TODO
const state = await this.getStateOrGenerate(blockNumber);
const isMint = _tokenOut == state.stablecoin.address;
let oracleValue: number;
let minRatio: number;
let minRatio: number = 0;
let collateral = _tokenIn;
if (isMint)
oracleValue = await this._readMint(this.config, state, _tokenIn);
Expand All @@ -178,6 +171,7 @@ export class AngleTransmuterEventPool extends ComposedEventSubscriber<PoolState>
const otherStablecoinIssued =
state.transmuter.totalStablecoinIssued - collatStablecoinIssued;
const fees = state.transmuter.collaterals[collateral].fees;

return _amounts.map(_amount => {
if (isMint && side == SwapSide.SELL)
return _quoteMintExactInput(
Expand Down Expand Up @@ -324,7 +318,6 @@ export class AngleTransmuterEventPool extends ComposedEventSubscriber<PoolState>
} else if (oracleFeed.isPyth) {
pythIds.ids = pythIds.ids.concat(oracleFeed.pyth!.feedIds);
} else {
// TODO fill the staked ETH feed
throw new Error('Unknown oracle feed');
}
return { chainlinkMap, backedMap, redstoneMap, pythIds };
Expand Down Expand Up @@ -523,7 +516,7 @@ export class AngleTransmuterEventPool extends ComposedEventSubscriber<PoolState>
targetPrice,
);
let ratio = 1;
if (targetPrice < oracleValue) ratio = oracleValue / targetPrice;
if (oracleValue < targetPrice) ratio = oracleValue / targetPrice;
return { oracleValue, ratio };
}
}
Expand Down
21 changes: 5 additions & 16 deletions src/dex/angle-transmuter/angle-transmuter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class AngleTransmuter
public static erc20Interface = new Interface(ERC20ABI);

readonly hasConstantPriceLargeAmounts = false;
// TODO: set true here if protocols works only with wrapped asset
readonly needWrapNative = true;

readonly isFeeOnTransferSupported = false;
Expand All @@ -52,7 +51,7 @@ export class AngleTransmuter
readonly network: Network,
readonly dexKey: string,
readonly dexHelper: IDexHelper,
protected adapters = Adapters[network] || {}, // TODO: add any additional optional params to support other fork DEXes
protected adapters = Adapters[network] || {},
protected params: DexParams = AngleTransmuterConfig[dexKey][network],
) {
super(dexHelper, dexKey);
Expand All @@ -65,7 +64,6 @@ export class AngleTransmuter
// for pricing requests. It is optional for a DEX to
// implement this function
async initializePricing(blockNumber: number) {
// TODO: complete me!
const config = await AngleTransmuterEventPool.getConfig(
this.params,
blockNumber,
Expand Down Expand Up @@ -100,7 +98,6 @@ export class AngleTransmuter
side: SwapSide,
blockNumber: number,
): Promise<string[]> {
// TODO: complete me!
if (this._knownAddress(srcToken, destToken))
return [`${this.dexKey}_${this.params.agEUR.address.toLowerCase()}`];
else return [];
Expand All @@ -118,7 +115,6 @@ export class AngleTransmuter
blockNumber: number,
limitPools?: string[],
): Promise<null | ExchangePrices<AngleTransmuterData>> {
// TODO: complete me!
const uniquePool = `${
this.dexKey
}_${this.params.agEUR.address.toLowerCase()}`;
Expand All @@ -136,6 +132,7 @@ export class AngleTransmuter
const amountsFloat = amounts.map(amount =>
parseFloat(formatUnits(amount.toString(), preProcessDecimals)),
);

const prices = await this.eventPools!.getAmountOut(
srcToken.address,
destToken.address,
Expand Down Expand Up @@ -171,7 +168,6 @@ export class AngleTransmuter
getCalldataGasCost(
poolPrices: PoolPrices<AngleTransmuterData>,
): number | number[] {
// TODO: update if there is any payload in getAdapterParam
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
}

Expand All @@ -186,7 +182,6 @@ export class AngleTransmuter
data: AngleTransmuterData,
side: SwapSide,
): AdapterExchangeParam {
// TODO: complete me!
const { exchange } = data;

// Encode here the payload for adapter
Expand All @@ -211,15 +206,14 @@ export class AngleTransmuter
data: AngleTransmuterData,
side: SwapSide,
): Promise<SimpleExchangeParam> {
// TODO: complete me!
const { exchange } = data;

// Encode here the transaction arguments
const swapData = TransmuterSubscriber.interface.encodeFunctionData(
side == SwapSide.SELL ? 'swapExactInput' : 'swapExactOutput',
[
srcAmount,
destAmount,
side == SwapSide.SELL ? srcAmount : destAmount,
side == SwapSide.SELL ? destAmount : srcAmount,
srcToken,
destToken,
this.augustusAddress,
Expand All @@ -243,7 +237,6 @@ export class AngleTransmuter
// getTopPoolsForToken. It is optional for a DEX
// to implement this
async updatePoolState(): Promise<void> {
// TODO: complete me!
if (!this.supportedTokens.length) {
let tokenAddresses = await AngleTransmuterEventPool.getCollateralsList(
this.params.transmuter,
Expand Down Expand Up @@ -317,7 +310,6 @@ export class AngleTransmuter
tokenAddress: Address,
limit: number,
): Promise<PoolLiquidity[]> {
//TODO: complete me!
if (!this.supportedTokens.some(t => t.address === tokenAddress)) return [];

const connectorTokens =
Expand All @@ -342,12 +334,9 @@ export class AngleTransmuter

// This is optional function in case if your implementation has acquired any resources
// you need to release for graceful shutdown. For example, it may be any interval timer
releaseResources(): AsyncOrSync<void> {
// TODO: complete me!
}
releaseResources(): AsyncOrSync<void> {}

_knownAddress(srcToken: Token, destToken: Token): boolean {
// TODO: complete me!
const srcAddress = this.dexHelper.config
.wrapETH(srcToken)
.address.toLowerCase();
Expand Down
2 changes: 0 additions & 2 deletions src/dex/angle-transmuter/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ export const AngleTransmuterConfig: DexConfigMap<DexParams> = {
};

export const Adapters: Record<number, AdapterMappings> = {
// TODO: add adapters for each chain
// This is an example to copy
[Network.MAINNET]: { [SwapSide.SELL]: [{ name: '', index: 0 }] },
};
4 changes: 2 additions & 2 deletions src/dex/angle-transmuter/pyth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class PythSubscriber<State> extends PartialEventSubscriber<
_state[decoded.id] = {
answer: this._processPrice(decoded.price, expo),
expo: expo,
timestamp: decoded.publishTime,
timestamp: Number(decoded.publishTime.toString()),
};
return _state;
}
Expand Down Expand Up @@ -84,7 +84,7 @@ export class PythSubscriber<State> extends PartialEventSubscriber<
_state[id] = {
answer: this._processPrice(decodedOracle[index].price, expo),
expo: expo,
timestamp: decodedOracle[index].publishTime,
timestamp: Number(decodedOracle[index].publishTime.toString()),
};
});
return _state;
Expand Down
Loading

0 comments on commit a8a3210

Please sign in to comment.