-
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.
feat: add position created to refinance simulator (#154)
- Loading branch information
Showing
46 changed files
with
488 additions
and
55 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
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
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
27 changes: 27 additions & 0 deletions
27
sdk/protocol-plugins/src/plugins/common/actions/PositionCreatedAction.ts
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,27 @@ | ||
import { ActionCall, BaseAction, InputSlotsMapping } from '@summerfi/protocol-plugins-common' | ||
import { Position } from '@summerfi/sdk-common/common' | ||
|
||
export class PositionCreatedAction extends BaseAction { | ||
public readonly config = { | ||
name: 'PositionCreated', | ||
version: 0, | ||
parametersAbi: | ||
'(string protocol, string positionType, address collateralToken, address debtToken)', | ||
storageInputs: [], | ||
storageOutputs: [], | ||
} as const | ||
|
||
public encodeCall(params: { position: Position }, paramsMapping?: InputSlotsMapping): ActionCall { | ||
return this._encodeCall({ | ||
arguments: [ | ||
{ | ||
protocol: params.position.pool.protocol.name, | ||
positionType: params.position.type, | ||
collateralToken: params.position.collateralAmount.token.address.value, | ||
debtToken: params.position.debtAmount.token.address.value, | ||
}, | ||
], | ||
mapping: paramsMapping, | ||
}) | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
sdk/protocol-plugins/src/plugins/common/builders/PositionCreatedActionBuilder.ts
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,19 @@ | ||
import { steps } from '@summerfi/sdk-common/simulation' | ||
import { ActionBuilder } from '@summerfi/protocol-plugins-common' | ||
import { PositionCreatedAction } from '../actions/PositionCreatedAction' | ||
|
||
export const PositionCreatedActionBuilder: ActionBuilder<steps.NewPositionEvent> = async ( | ||
params, | ||
): Promise<void> => { | ||
const { context, step } = params | ||
|
||
context.addActionCall({ | ||
step: step, | ||
action: new PositionCreatedAction(), | ||
arguments: { | ||
position: step.inputs.position, | ||
}, | ||
connectedInputs: {}, | ||
connectedOutputs: {}, | ||
}) | ||
} |
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
96 changes: 96 additions & 0 deletions
96
sdk/protocol-plugins/tests/actions/PositionCreatedAction.spec.ts
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,96 @@ | ||
import { Address, Position, Token, TokenAmount, PositionType } from '@summerfi/sdk-common/common' | ||
import { decodeActionCalldata, getTargetHash } from '@summerfi/testing-utils' | ||
import { PositionCreatedAction } from '../../src/plugins/common/actions/PositionCreatedAction' | ||
import { IProtocol, PoolType, ProtocolName } from '@summerfi/sdk-common/protocols' | ||
import { MakerPoolId } from '../../src/plugins/maker/types/MakerPoolId' | ||
import { ILKType } from '../../src/plugins/maker' | ||
|
||
describe('PositionCreated Action', () => { | ||
const action = new PositionCreatedAction() | ||
const contractNameWithVersion = `${action.config.name}` | ||
|
||
const DAI = Token.createFrom({ | ||
chainInfo: { | ||
name: 'Mainnet', | ||
chainId: 1, | ||
}, | ||
address: Address.createFromEthereum({ value: '0x6B175474E89094C44Da98b954EedeAC495271d0F' }), | ||
decimals: 18, | ||
name: 'Dai Stablecoin', | ||
symbol: 'DAI', | ||
}) | ||
|
||
const WETH = Token.createFrom({ | ||
chainInfo: { | ||
name: 'Mainnet', | ||
chainId: 1, | ||
}, | ||
address: Address.createFromEthereum({ value: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' }), | ||
decimals: 18, | ||
name: 'Wrapped Ether', | ||
symbol: 'WETH', | ||
}) | ||
|
||
const protocol: IProtocol = { | ||
name: ProtocolName.Spark, | ||
chainInfo: { | ||
name: 'Mainnet', | ||
chainId: 1, | ||
}, | ||
} | ||
|
||
const position = Position.createFrom({ | ||
type: PositionType.Multiply, | ||
positionId: { | ||
id: '0x123', | ||
}, | ||
pool: { | ||
type: PoolType.Lending, | ||
protocol: protocol, | ||
poolId: { | ||
protocol: protocol, | ||
vaultId: '0x123', | ||
ilkType: ILKType.ETH_A, | ||
} as MakerPoolId, | ||
}, | ||
debtAmount: TokenAmount.createFrom({ | ||
token: DAI, | ||
amount: '100', | ||
}), | ||
collateralAmount: TokenAmount.createFrom({ | ||
token: WETH, | ||
amount: '100', | ||
}), | ||
}) | ||
|
||
it('should return the versioned name', () => { | ||
expect(action.getVersionedName()).toBe(contractNameWithVersion) | ||
}) | ||
|
||
it('should encode calls', async () => { | ||
const call = action.encodeCall( | ||
{ | ||
position: position, | ||
}, | ||
[8, 9, 1, 3], | ||
) | ||
|
||
expect(call.targetHash).toBe(getTargetHash(action)) | ||
|
||
const actionDecodedArgs = decodeActionCalldata({ | ||
action, | ||
calldata: call.callData, | ||
}) | ||
|
||
expect(actionDecodedArgs).toBeDefined() | ||
expect(actionDecodedArgs?.args).toEqual([ | ||
{ | ||
protocol: protocol.name, | ||
positionType: position.type, | ||
collateralToken: WETH.address.value, | ||
debtToken: DAI.address.value, | ||
}, | ||
]) | ||
expect(actionDecodedArgs?.mapping).toEqual([8, 9, 1, 3]) | ||
}) | ||
}) |
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
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,4 @@ | ||
export enum PositionType { | ||
Borrow = 'Borrow', | ||
Multiply = 'Multiply', | ||
} |
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
Oops, something went wrong.