-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from mangrovedao/feat/addLogics
feat: logics
- Loading branch information
Showing
12 changed files
with
287 additions
and
12 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,6 @@ | ||
--- | ||
"@mangrovedao/mgv": minor | ||
--- | ||
|
||
Added routing logics | ||
Added midPrice and spread calculation to getBook |
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,23 @@ | ||
import { aaveBalance, aaveOverLying } from '../strategies/aave.js' | ||
import { buildLogic } from '../utils.js' | ||
|
||
export const blastOrbitLogic = buildLogic( | ||
'Orbit', | ||
'0x3870DAFB80713cad59Dd999c85b1E46314b41e9c', | ||
aaveOverLying, | ||
aaveBalance, | ||
) | ||
|
||
export const blastZeroLendLogic = buildLogic( | ||
'ZeroLend', | ||
'0x5126d161210654148445AdB3053e6DE2bbeaeefB', | ||
aaveOverLying, | ||
aaveBalance, | ||
) | ||
|
||
export const blastPacFinanceLogic = buildLogic( | ||
'PacFinance', | ||
'0x982A72Afe26C72F7bef644164942BFc1d5D025F8', | ||
aaveOverLying, | ||
aaveBalance, | ||
) |
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,5 @@ | ||
export { | ||
blastOrbitLogic, | ||
blastZeroLendLogic, | ||
blastPacFinanceLogic, | ||
} from './blast.js' |
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,24 @@ | ||
export { | ||
blastOrbitLogic, | ||
blastZeroLendLogic, | ||
blastPacFinanceLogic, | ||
} from './chains/index.js' | ||
|
||
export { | ||
balanceLogicABI, | ||
baseBalance, | ||
aaveLogicABI, | ||
aaveBalance, | ||
aaveOverLying, | ||
} from './strategies/index.js' | ||
|
||
export type { | ||
OverlyingParams, | ||
OverlyingResponse, | ||
RoutingLogicOverlying, | ||
LogicBalanceParams, | ||
LogicBalanceResponse, | ||
RoutingLogicBalance, | ||
} from './utils.js' | ||
|
||
export { buildLogic } from './utils.js' |
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,31 @@ | ||
import { isAddressEqual, parseAbi, zeroAddress } from 'viem' | ||
import type { RoutingLogicOverlying } from '../utils.js' | ||
import { baseBalance } from './base.js' | ||
|
||
export const aaveLogicABI = parseAbi([ | ||
'function overlying(address asset) public view returns (address aToken)', | ||
]) | ||
|
||
export const aaveOverLying: RoutingLogicOverlying< | ||
typeof aaveLogicABI, | ||
'view', | ||
'overlying' | ||
> = { | ||
getOverlyingContractParams(params) { | ||
return { | ||
address: params.token, | ||
abi: aaveLogicABI, | ||
functionName: 'overlying', | ||
args: [params.token], | ||
} | ||
}, | ||
parseOverlyingContractResponse(response) { | ||
return { | ||
type: 'erc20', | ||
token: response, | ||
available: !isAddressEqual(response, zeroAddress), | ||
} | ||
}, | ||
} | ||
|
||
export const aaveBalance = baseBalance |
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,24 @@ | ||
import { parseAbi } from 'viem' | ||
import type { RoutingLogicBalance } from '../utils.js' | ||
|
||
export const balanceLogicABI = parseAbi([ | ||
'function balanceLogic(address token, address fundOwner) external view returns (uint balance)', | ||
]) | ||
|
||
export const baseBalance: RoutingLogicBalance< | ||
typeof balanceLogicABI, | ||
'view', | ||
'balanceLogic' | ||
> = { | ||
getRoutingLogicBalanceParams(params) { | ||
return { | ||
address: params.logic, | ||
abi: balanceLogicABI, | ||
functionName: 'balanceLogic', | ||
args: [params.token, params.user], | ||
} | ||
}, | ||
parseRoutingLogicBalanceResponse(response) { | ||
return response | ||
}, | ||
} |
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,10 @@ | ||
export { | ||
balanceLogicABI, | ||
baseBalance, | ||
} from './base.js' | ||
|
||
export { | ||
aaveLogicABI, | ||
aaveOverLying, | ||
aaveBalance, | ||
} from './aave.js' |
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,98 @@ | ||
import type { | ||
Abi, | ||
AbiStateMutability, | ||
Address, | ||
ContractFunctionName, | ||
ContractFunctionParameters, | ||
ContractFunctionReturnType, | ||
} from 'viem' | ||
|
||
export type OverlyingParams = { | ||
token: Address | ||
logic: Address | ||
name: string | ||
} | ||
|
||
export type OverlyingResponse = { | ||
type: 'erc20' | 'erc721' | ||
token: Address | ||
available: boolean | ||
} | ||
|
||
export type RoutingLogicOverlying< | ||
abi extends Abi | readonly unknown[] = Abi, | ||
mutability extends AbiStateMutability = AbiStateMutability, | ||
functionName extends ContractFunctionName< | ||
abi, | ||
mutability | ||
> = ContractFunctionName<abi, mutability>, | ||
> = { | ||
getOverlyingContractParams: ( | ||
params: OverlyingParams, | ||
) => ContractFunctionParameters<abi, mutability, functionName> | ||
parseOverlyingContractResponse: ( | ||
response: ContractFunctionReturnType<abi, mutability, functionName>, | ||
) => OverlyingResponse | ||
} | ||
|
||
export type LogicBalanceParams = { | ||
token: Address | ||
logic: Address | ||
name: string | ||
user: Address | ||
} | ||
|
||
export type LogicBalanceResponse = bigint | ||
|
||
export type RoutingLogicBalance< | ||
abi extends Abi | readonly unknown[] = Abi, | ||
mutability extends AbiStateMutability = AbiStateMutability, | ||
functionName extends ContractFunctionName< | ||
abi, | ||
mutability | ||
> = ContractFunctionName<abi, mutability>, | ||
> = { | ||
getRoutingLogicBalanceParams: ( | ||
params: LogicBalanceParams, | ||
) => ContractFunctionParameters<abi, mutability, functionName> | ||
parseRoutingLogicBalanceResponse: ( | ||
response: ContractFunctionReturnType<abi, mutability, functionName>, | ||
) => LogicBalanceResponse | ||
} | ||
|
||
export function buildLogic< | ||
TName extends string = string, | ||
TLogicAddress extends Address = Address, | ||
abiOverlying extends Abi | readonly unknown[] = Abi, | ||
mutabilityOverlying extends AbiStateMutability = AbiStateMutability, | ||
functionNameOverlying extends ContractFunctionName< | ||
abiOverlying, | ||
mutabilityOverlying | ||
> = ContractFunctionName<abiOverlying, mutabilityOverlying>, | ||
abiBalance extends Abi | readonly unknown[] = Abi, | ||
mutabilityBalance extends AbiStateMutability = AbiStateMutability, | ||
functionNameBalance extends ContractFunctionName< | ||
abiBalance, | ||
mutabilityBalance | ||
> = ContractFunctionName<abiBalance, mutabilityBalance>, | ||
>( | ||
name: TName, | ||
logic: TLogicAddress, | ||
logicOverlying: RoutingLogicOverlying< | ||
abiOverlying, | ||
mutabilityOverlying, | ||
functionNameOverlying | ||
>, | ||
logicBalance: RoutingLogicBalance< | ||
abiBalance, | ||
mutabilityBalance, | ||
functionNameBalance | ||
>, | ||
) { | ||
return { | ||
name, | ||
logic, | ||
logicOverlying, | ||
logicBalance, | ||
} | ||
} |
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