-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
861 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
} |
Oops, something went wrong.