Skip to content

Commit

Permalink
solve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Oct 6, 2023
2 parents a3019d0 + 71a0281 commit 54821c0
Show file tree
Hide file tree
Showing 18 changed files with 861 additions and 13 deletions.
300 changes: 300 additions & 0 deletions src/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
[
{
"inputs": [
{ "internalType": "address", "name": "_poolDeployer", "type": "address" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint24",
"name": "fee",
"type": "uint24"
},
{
"indexed": true,
"internalType": "int24",
"name": "tickSpacing",
"type": "int24"
}
],
"name": "FeeAmountEnabled",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint24",
"name": "fee",
"type": "uint24"
},
{
"indexed": false,
"internalType": "bool",
"name": "whitelistRequested",
"type": "bool"
},
{
"indexed": false,
"internalType": "bool",
"name": "enabled",
"type": "bool"
}
],
"name": "FeeAmountExtraInfoUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "oldOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnerChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "token0",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "token1",
"type": "address"
},
{
"indexed": true,
"internalType": "uint24",
"name": "fee",
"type": "uint24"
},
{
"indexed": false,
"internalType": "int24",
"name": "tickSpacing",
"type": "int24"
},
{
"indexed": false,
"internalType": "address",
"name": "pool",
"type": "address"
}
],
"name": "PoolCreated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "lmPoolDeployer",
"type": "address"
}
],
"name": "SetLmPoolDeployer",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": false,
"internalType": "bool",
"name": "verified",
"type": "bool"
}
],
"name": "WhiteListAdded",
"type": "event"
},
{
"inputs": [
{ "internalType": "address", "name": "pool", "type": "address" },
{ "internalType": "address", "name": "recipient", "type": "address" },
{
"internalType": "uint128",
"name": "amount0Requested",
"type": "uint128"
},
{
"internalType": "uint128",
"name": "amount1Requested",
"type": "uint128"
}
],
"name": "collectProtocol",
"outputs": [
{ "internalType": "uint128", "name": "amount0", "type": "uint128" },
{ "internalType": "uint128", "name": "amount1", "type": "uint128" }
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "tokenA", "type": "address" },
{ "internalType": "address", "name": "tokenB", "type": "address" },
{ "internalType": "uint24", "name": "fee", "type": "uint24" }
],
"name": "createPool",
"outputs": [
{ "internalType": "address", "name": "pool", "type": "address" }
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint24", "name": "fee", "type": "uint24" },
{ "internalType": "int24", "name": "tickSpacing", "type": "int24" }
],
"name": "enableFeeAmount",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "uint24", "name": "", "type": "uint24" }],
"name": "feeAmountTickSpacing",
"outputs": [{ "internalType": "int24", "name": "", "type": "int24" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint24", "name": "", "type": "uint24" }],
"name": "feeAmountTickSpacingExtraInfo",
"outputs": [
{ "internalType": "bool", "name": "whitelistRequested", "type": "bool" },
{ "internalType": "bool", "name": "enabled", "type": "bool" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "", "type": "address" },
{ "internalType": "address", "name": "", "type": "address" },
{ "internalType": "uint24", "name": "", "type": "uint24" }
],
"name": "getPool",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "lmPoolDeployer",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "poolDeployer",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint24", "name": "fee", "type": "uint24" },
{ "internalType": "bool", "name": "whitelistRequested", "type": "bool" },
{ "internalType": "bool", "name": "enabled", "type": "bool" }
],
"name": "setFeeAmountExtraInfo",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "pool", "type": "address" },
{ "internalType": "uint32", "name": "feeProtocol0", "type": "uint32" },
{ "internalType": "uint32", "name": "feeProtocol1", "type": "uint32" }
],
"name": "setFeeProtocol",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "pool", "type": "address" },
{ "internalType": "address", "name": "lmPool", "type": "address" }
],
"name": "setLmPool",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_lmPoolDeployer",
"type": "address"
}
],
"name": "setLmPoolDeployer",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "_owner", "type": "address" }
],
"name": "setOwner",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "user", "type": "address" },
{ "internalType": "bool", "name": "verified", "type": "bool" }
],
"name": "setWhiteListAddress",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
4 changes: 4 additions & 0 deletions src/dex-helper/dummy-dex-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class DummyCache implements ICache {
return 0;
}

async zrem(key: string, membersKeys: string[]): Promise<number> {
return 0;
}

async zadd(key: string, bulkItemsToAdd: (number | string)[], option?: 'NX') {
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/dex-helper/icache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export interface ICache {

zremrangebyscore(key: string, min: number, max: number): Promise<number>;

zrem(key: string, membersKeys: string[]): Promise<number>;

zscore(setKey: string, key: string): Promise<string | null>;

sismember(setKey: string, key: string): Promise<boolean>;
Expand Down
70 changes: 70 additions & 0 deletions src/dex/algebra/algebra-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Interface } from '@ethersproject/abi';
import { DeepReadonly } from 'ts-essentials';
import FactoryABI from '../../abi/algebra/AlgebraFactory-v1_1.abi.json';
import { IDexHelper } from '../../dex-helper/idex-helper';
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
import { Address, Log, Logger } from '../../types';
import { LogDescription } from 'ethers/lib/utils';
import { FactoryState } from './types';

export type OnPoolCreatedCallback = ({
token0,
token1,
}: {
token0: string;
token1: string;
}) => Promise<void>;

/*
* "Stateless" event subscriber in order to capture "PoolCreated" event on new pools created.
* State is present, but it's a placeholder to actually make the events reach handlers (if there's no previous state - `processBlockLogs` is not called)
*/
export class AlgebraFactory extends StatefulEventSubscriber<FactoryState> {
handlers: {
[event: string]: (event: any) => Promise<void>;
} = {};

logDecoder: (log: Log) => any;

public readonly factoryIface = new Interface(FactoryABI);

constructor(
readonly dexHelper: IDexHelper,
parentName: string,
protected readonly factoryAddress: Address,
logger: Logger,
protected readonly onPoolCreated: OnPoolCreatedCallback,
mapKey: string = '',
) {
super(parentName, `${parentName} Factory`, dexHelper, logger, true, mapKey);

this.addressesSubscribed = [factoryAddress];

this.logDecoder = (log: Log) => this.factoryIface.parseLog(log);

this.handlers['Pool'] = this.handleNewPool.bind(this);
}

generateState(): FactoryState {
return {};
}

protected async processLog(
_: DeepReadonly<FactoryState>,
log: Readonly<Log>,
): Promise<FactoryState> {
const event = this.logDecoder(log);
if (event.name in this.handlers) {
await this.handlers[event.name](event);
}

return {};
}

async handleNewPool(event: LogDescription) {
const token0 = event.args.token0;
const token1 = event.args.token1;

await this.onPoolCreated({ token0, token1 });
}
}
Loading

0 comments on commit 54821c0

Please sign in to comment.