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

feat: add any pair capability to refinance strategy #153

Merged
merged 32 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c5f4f87
feat: add OneInch protocols to quote response and map to QuoteData ro…
zerotucks Mar 25, 2024
ed8a1f4
feat: add swaps to Simulate state and SwapReducer
zerotucks Mar 25, 2024
cc1d61e
feat: add swaps to Refinance strategy output
zerotucks Mar 25, 2024
1fa7f2f
refactor: clear up imports and deps issues
zerotucks Mar 25, 2024
8346e41
refactor: fix imports and format
zerotucks Mar 26, 2024
e0d2d7c
refactor: strip estimatedGas from SimulatedSwapData type
zerotucks Mar 26, 2024
5668608
feat: determine if Swaps should be included based on targetCollateral…
zerotucks Mar 26, 2024
7d09319
test: WIP work on refinance tests with swap
zerotucks Mar 26, 2024
61ec9b1
feat: extend simulatedSwapData to include offerPrice, marketPrice and…
zerotucks Mar 26, 2024
741cbf5
chore: address PR comments & fix tests
zerotucks Mar 26, 2024
9b7c63b
Merge branch 'dev' into jt/sc-14942/provide-swap-data-view-for-fe
zerotucks Mar 26, 2024
419063e
Merge branch 'jt/sc-14942/provide-swap-data-view-for-fe' into jt/sc-1…
zerotucks Mar 27, 2024
60c8d37
feat: calculate borrowAmount when swapping debt
zerotucks Mar 28, 2024
43fe186
tests: fix remaining issues with build and tests
zerotucks Mar 28, 2024
5a86985
feat: add summerFee resolver to SwapManager
zerotucks Mar 28, 2024
d80f20b
refactor: replace applyPercentage with subtract
zerotucks Mar 28, 2024
c6b3f9d
chore: fix minor issues
zerotucks Mar 28, 2024
4659ec0
test: fix issues with e2e's
zerotucks Mar 28, 2024
f36d761
chore: address PR comments
zerotucks Apr 3, 2024
d9ddcf0
Merge branch 'dev' into jt/sc-14942/provide-swap-data-view-for-fe
zerotucks Apr 3, 2024
4321824
fix: merge issues
zerotucks Apr 3, 2024
47f8b82
Merge branch 'jt/sc-14942/provide-swap-data-view-for-fe' into jt/sc-1…
zerotucks Apr 3, 2024
2d0d5c4
refactor: Refinance params to source -> target position
zerotucks Apr 3, 2024
f2b43c4
refactor: strip fromBaseUnit methods
zerotucks Apr 3, 2024
2cbc242
Merge branch 'dev' into jt/sc-14939/add-any-pair-to-simulator-order-p…
zerotucks Apr 3, 2024
d999234
fix: PR comments
zerotucks Apr 4, 2024
fdac1f1
refactor: add skip as second arg to avoid running steps that are not …
zerotucks Apr 4, 2024
309be54
refactor: add v6 from 1inch provider
zerotucks Apr 4, 2024
3cae971
Merge branch 'dev' into jt/sc-14939/add-any-pair-to-simulator-order-p…
zerotucks Apr 5, 2024
39689f0
chore: format
zerotucks Apr 5, 2024
7fafa72
refactor: try to clarify differences between older 1inch api and newe…
zerotucks Apr 5, 2024
320cfc0
chore: fix formatting
zerotucks Apr 5, 2024
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
3 changes: 3 additions & 0 deletions .github/workflows/build-integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jobs:
ONE_INCH_API_KEY: ${{ secrets.ONE_INCH_API_KEY }}
ONE_INCH_API_VERSION: ${{ secrets.ONE_INCH_API_VERSION }}
ONE_INCH_API_URL: ${{ secrets.ONE_INCH_API_URL }}
ONE_INCH_API_SPOT_KEY: ${{ secrets.ONE_INCH_API_SPOT_KEY }}
ONE_INCH_API_SPOT_VERSION: ${{ secrets.ONE_INCH_API_SPOT_VERSION }}
ONE_INCH_API_SPOT_URL: ${{ secrets.ONE_INCH_API_SPOT_URL }}
ONE_INCH_ALLOWED_SWAP_PROTOCOLS: ${{ secrets.ONE_INCH_ALLOWED_SWAP_PROTOCOLS }}
ONE_INCH_SWAP_CHAIN_IDS: ${{ secrets.ONE_INCH_SWAP_CHAIN_IDS }}
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
3 changes: 3 additions & 0 deletions .github/workflows/build-unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jobs:
ONE_INCH_API_KEY: ${{ secrets.ONE_INCH_API_KEY }}
ONE_INCH_API_VERSION: ${{ secrets.ONE_INCH_API_VERSION }}
ONE_INCH_API_URL: ${{ secrets.ONE_INCH_API_URL }}
ONE_INCH_API_SPOT_KEY: ${{ secrets.ONE_INCH_API_SPOT_KEY }}
ONE_INCH_API_SPOT_VERSION: ${{ secrets.ONE_INCH_API_SPOT_VERSION }}
ONE_INCH_API_SPOT_URL: ${{ secrets.ONE_INCH_API_SPOT_URL }}
ONE_INCH_ALLOWED_SWAP_PROTOCOLS: ${{ secrets.ONE_INCH_ALLOWED_SWAP_PROTOCOLS }}
ONE_INCH_SWAP_CHAIN_IDS: ${{ secrets.ONE_INCH_SWAP_CHAIN_IDS }}
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { ConfigItem } from '../types/ConfigItem'
import { ConfigKey } from '../types/ConfigKey'

const CONFIG_KEYS: ConfigKey[] = [
'ONE_INCH_API_KEY',
'ONE_INCH_API_VERSION',
'ONE_INCH_API_KEY',
'ONE_INCH_API_URL',
'ONE_INCH_API_SPOT_KEY',
'ONE_INCH_API_SPOT_URL',
'ONE_INCH_API_SPOT_VERSION',
'ONE_INCH_ALLOWED_SWAP_PROTOCOLS',
'ONE_INCH_SWAP_CHAIN_IDS',
]
Expand Down
89 changes: 0 additions & 89 deletions sdk/order-planner-service/tests/mocks/SwapManagerMock.ts
Original file line number Diff line number Diff line change
@@ -1,89 +0,0 @@
import { Address, ChainInfo, Percentage, Token, TokenAmount } from '@summerfi/sdk-common/common'
import { ISwapManager } from '@summerfi/swap-common/interfaces'
import { QuoteData, SwapData, SpotData } from '@summerfi/sdk-common/swap'

export class SwapManagerMock implements ISwapManager {
private _swapDataReturnValue: SwapData = {} as SwapData
private _quoteDataReturnValue: QuoteData = {} as QuoteData
private _spotDataReturnValue: SpotData = {} as SpotData

private _lastGetSwapDataExactInputParams:
| {
chainInfo: ChainInfo
fromAmount: TokenAmount
toToken: Token
recipient: Address
slippage: Percentage
}
| undefined

private _lastGetSwapQuoteExactInputParams:
| {
chainInfo: ChainInfo
fromAmount: TokenAmount
toToken: Token
}
| undefined

setSwapData(swapData: SwapData): void {
this._swapDataReturnValue = swapData
}

setQuoteData(quoteData: QuoteData): void {
this._quoteDataReturnValue = quoteData
}

async getSwapDataExactInput(params: {
chainInfo: ChainInfo
fromAmount: TokenAmount
toToken: Token
recipient: Address
slippage: Percentage
}): Promise<SwapData> {
this._lastGetSwapDataExactInputParams = params
return this._swapDataReturnValue
}

async getSwapQuoteExactInput(params: {
chainInfo: ChainInfo
fromAmount: TokenAmount
toToken: Token
}): Promise<QuoteData> {
this._lastGetSwapQuoteExactInputParams = params
return this._quoteDataReturnValue
}

async getSpotPrices(params: { chainInfo: ChainInfo; tokens: Token[] }): Promise<SpotData> {
return this._spotDataReturnValue
}

get swapDataReturnValue(): SwapData {
return this._swapDataReturnValue
}

get quoteDataReturnValue(): QuoteData {
return this._quoteDataReturnValue
}

get lastGetSwapDataExactInputParams():
| {
chainInfo: ChainInfo
fromAmount: TokenAmount
toToken: Token
recipient: Address
slippage: Percentage
}
| undefined {
return this._lastGetSwapDataExactInputParams
}

get lastGetSwapQuoteExactInputParams():
| {
chainInfo: ChainInfo
fromAmount: TokenAmount
toToken: Token
}
| undefined {
return this._lastGetSwapQuoteExactInputParams
}
}
12 changes: 0 additions & 12 deletions sdk/order-planner-service/tests/mocks/UserMock.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import { DeploymentIndex } from '@summerfi/deployment-utils'
import { ISwapManager } from '@summerfi/swap-common/interfaces'
import { Address, AddressValue, ChainFamilyMap, ChainInfo } from '@summerfi/sdk-common/common'
import { ProtocolName } from '@summerfi/sdk-common/protocols'
import { SwapManagerMock, UserMock } from '@summerfi/testing-utils'
import { IPositionsManager } from '@summerfi/sdk-common/orders'
import { SetupDeployments } from '../utils/SetupDeployments'
import { UserMock } from '../mocks/UserMock'
import { SwapManagerMock } from '../mocks/SwapManagerMock'
import { getRefinanceSimulation } from '../utils/RefinanceSimulation/RefinanceSimulation'
import { OrderPlannerService } from '../../src/implementation/OrderPlannerService'
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const SwapActionBuilder: ActionBuilder<steps.SwapStep> = async (params):
arguments: {
fromAmount: step.inputs.fromTokenAmount,
toMinimumAmount: step.inputs.toTokenAmount,
fee: step.inputs.fee,
fee: step.inputs.summerFee,
withData: swapData.calldata,
collectFeeInFromToken: true,
},
Expand Down
14 changes: 6 additions & 8 deletions sdk/protocol-plugins/tests/builders/SwapActionBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ describe('Swap Action Builder', () => {
routes: [],
fromTokenAmount: fromAmount,
toTokenAmount: toAmount,
prices: [
Price.createFrom({
value: '0',
quoteToken: fromAmount.token,
baseToken: toAmount.token,
}),
],
fee: fee,
spotPrice: Price.createFrom({
value: '0',
quoteToken: fromAmount.token,
baseToken: toAmount.token,
}),
summerFee: fee,
slippage,
},
outputs: {
Expand Down
73 changes: 0 additions & 73 deletions sdk/protocol-plugins/tests/tests.spec.ts

This file was deleted.

3 changes: 2 additions & 1 deletion sdk/sdk-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"devDependencies": {
"@summerfi/eslint-config": "workspace:*",
"@summerfi/jest-config": "workspace:*",
"@summerfi/typescript-config": "workspace:*"
"@summerfi/typescript-config": "workspace:*",
"@summerfi/testing-utils": "workspace:*"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ export class RefinanceSimulationManager extends IRPCClient {
params: IRefinanceParameters,
): Promise<ISimulation<SimulationType.Refinance>> {
const refinanceParameters: IRefinanceParameters = {
position: {
type: params.position.type,
positionId: params.position.positionId,
debtAmount: params.position.debtAmount,
collateralAmount: params.position.collateralAmount,
sourcePosition: {
type: params.sourcePosition.type,
positionId: params.sourcePosition.positionId,
debtAmount: params.sourcePosition.debtAmount,
collateralAmount: params.sourcePosition.collateralAmount,
pool: {
poolId: params.position.pool.poolId,
protocol: params.position.pool.protocol,
type: params.position.pool.type,
poolId: params.sourcePosition.pool.poolId,
protocol: params.sourcePosition.pool.protocol,
type: params.sourcePosition.pool.type,
},
},
targetPool: {
poolId: params.targetPool.poolId,
protocol: params.targetPool.protocol,
type: params.targetPool.type,
targetPosition: {
type: params.targetPosition.type,
positionId: params.targetPosition.positionId,
debtAmount: params.targetPosition.debtAmount,
collateralAmount: params.targetPosition.collateralAmount,
pool: {
poolId: params.targetPosition.pool.poolId,
protocol: params.targetPosition.pool.protocol,
type: params.targetPosition.pool.type,
},
},
slippage: params.slippage,
}
Expand Down
Loading
Loading