diff --git a/packages/core-contracts/contracts/actions/spark/Payback.sol b/packages/core-contracts/contracts/actions/spark/Payback.sol index b59d884a66..42bb37b6da 100644 --- a/packages/core-contracts/contracts/actions/spark/Payback.sol +++ b/packages/core-contracts/contracts/actions/spark/Payback.sol @@ -29,11 +29,15 @@ contract SparkPayback is Executable, UseStore { payback.amount = store().readUint(bytes32(payback.amount), paramsMap[1], address(this)); + if (payback.onBehalf == address(0)) { + payback.onBehalf = address(this); + } + IPool(registry.getRegisteredService(SPARK_LENDING_POOL)).repay( payback.asset, payback.paybackAll ? type(uint256).max : payback.amount, 2, - address(this) + payback.onBehalf ); store().write(bytes32(payback.amount)); @@ -42,4 +46,4 @@ contract SparkPayback is Executable, UseStore { function parseInputs(bytes memory _callData) public pure returns (PaybackData memory params) { return abi.decode(_callData, (PaybackData)); } -} +} \ No newline at end of file diff --git a/packages/core-contracts/contracts/core/types/Spark.sol b/packages/core-contracts/contracts/core/types/Spark.sol index 05c93767d4..3081efda6a 100644 --- a/packages/core-contracts/contracts/core/types/Spark.sol +++ b/packages/core-contracts/contracts/core/types/Spark.sol @@ -24,6 +24,7 @@ struct PaybackData { address asset; uint256 amount; bool paybackAll; + address onBehalf; } /** diff --git a/sdk/protocol-plugins/src/plugins/spark/actions/SparkPaybackAction.ts b/sdk/protocol-plugins/src/plugins/spark/actions/SparkPaybackAction.ts index 910cd68569..e263e55bb0 100644 --- a/sdk/protocol-plugins/src/plugins/spark/actions/SparkPaybackAction.ts +++ b/sdk/protocol-plugins/src/plugins/spark/actions/SparkPaybackAction.ts @@ -1,11 +1,12 @@ import { ActionCall, BaseAction, InputSlotsMapping } from '@summerfi/protocol-plugins-common' +import { IAddress } from '@summerfi/sdk-common' import { ITokenAmount } from '@summerfi/sdk-common/common' export class SparkPaybackAction extends BaseAction { public static readonly Config = { name: 'SparkPayback', version: 2, - parametersAbi: ['(address asset, uint256 amount, bool paybackAll)'], + parametersAbi: ['(address asset, uint256 amount, bool paybackAll, address onBehalf)'], storageInputs: ['asset', 'amountToPayback'], storageOutputs: ['paybackedAmount'], } as const @@ -14,6 +15,7 @@ export class SparkPaybackAction extends BaseAction): Promise { - const { context, step, addressBookManager, user } = params + const { context, step, addressBookManager, user, positionsManager } = params if (!isSparkLendingPool(step.inputs.position.pool)) { throw new Error('Invalid Spark lending pool') @@ -57,6 +57,7 @@ export class SparkPaybackWithdrawActionBuilder extends BaseActionBuilder { { paybackAmount: tokenAmount, paybackAll: true, + onBehalf: onBehalf, }, [2, 6, 7, 9], ) @@ -47,6 +48,7 @@ describe('SparkPaybackAction Action', () => { asset: tokenAmount.token.address.value, amount: BigInt(tokenAmount.toBaseUnit()), paybackAll: true, + onBehalf: onBehalf.value, }, ]) expect(actionDecodedArgs?.mapping).toEqual([2, 6, 7, 9])