Note: the following example scripts are Solidity langauge based on Foundry framework.
Recap from here.
You can open/adjust with the position via the bank contract by calling bank.execute(position_id, spell_address, data)
function.
position_id
: your position Id, set it to be 0 if you want to open a new position.spell_address
: spell contract address that interacts with your target DEX.data
: describes what parameters we uses and what function we call in the spell contract, encoded as bytes data.
After execution, it will return your position_id
. (It must be equal to what you input or new position_id
if you set it as 0).
Different DEXes require different inputs.
Spell Address: See appendix A
Example of how to integrate with Homora here
Functions:
- addLiquidityWMasterChef: Leverage, provide liquidity to the pool and stake LP to the staking contract.
- removeLiquidityWMasterChef: unstake LP, remove liquidity from the pool and repay a loan.
- harvestWMasterChef: collect masterchef rewards.
- migrate: migrate position from SpookyswapV1 to SpookyswapV2
Decoding wrapper token ID
parameters | description |
---|---|
pid | pool id in SpookySwap's masterchefV2 |
rewardPerShare | latest-updated accumulated reward per share (being used for calculating pending reward) |
IBankFTM bank = IBankFTM(0x060E91A44f16DFcc1e2c427A0383596e1D2e886f);
uint256 positionId = 123; // change position id here
(
,
address collateralTokenAddress,
uint256 collateralId,
uint256 collateralAmount
) = bank.getPositionInfo(positionId);
IWMasterChefBooV2 wrapper = IWMasterChefBooV2(collateralTokenAddress);
(uint256 pid, uint256 rewardPerShare) = wrapper.decodeId(
collateralId
);
Spell Address: See appendix A
Example of how to integrate with Homora here
Functions:
- addLiquidityWMasterChef: Leverage, provide liquidity to the pool and stake LP to the staking contract.
- removeLiquidityWMasterChef: unstake LP, remove liquidity from the pool and repay a loan.
- harvestWMasterChef: collect masterchef rewards.
Decoding wrapper token ID
parameters | description |
---|---|
pid | pool id in SpiritSwap's masterchef |
rewardPerShare | latest-updated accumulated reward per share (being used for calculating pending reward) |
IBankFTM bank = IBankFTM(0x060E91A44f16DFcc1e2c427A0383596e1D2e886f);
uint256 positionId = 123; // change position id here
(
,
address collateralTokenAddress,
uint256 collateralId,
uint256 collateralAmount
) = bank.getPositionInfo(positionId);
IWMasterChefSpirit wrapper = IWMasterChefSpirit(collateralTokenAddress);
(uint256 pid, uint256 rewardPerShare) = wrapper.decodeId(
collateralId
);
Spell Address: See Appendix A
Example of how to integrate with Homora here
Functions:
- addLiquidityWMasterChef: Leverage, provide liquidity to the pool and stake LP to the staking contract.
- removeLiquidityWMasterChef: unstake LP, remove liquidity from the pool and repay a loan.
- harvestWMasterChef: collect masterchef rewards.
Decoding wrapper token ID
parameters | description |
---|---|
pid | pool id in Beet's masterchef |
rewardPerShare | latest-updated accumulated reward per share (being used for calculating pending reward) |
IBankFTM bank = IBankFTM(0x060E91A44f16DFcc1e2c427A0383596e1D2e886f);
uint256 positionId = 123; // change position id here
(
,
address collateralTokenAddress,
uint256 collateralId,
uint256 collateralAmount
) = bank.getPositionInfo(positionId);
IWMasterChefBeetsWorker wrapper = IWMasterChefBeetsWorker(collateralTokenAddress);
(uint256 pid, uint256 rewardPerShare) = wrapper.decodeId(
collateralId
);
Many wrapper contracts are implemented to support different pools' reward contract. Even the pools are in the same DEX, the reward contract may be different, e.g. Masterchef contract, Minichef contract),
Following table describes what wrapper contract types use which spell contracts.
Pool type | Wrapper contracts | Spell contracts |
---|---|---|
SpookySwap | WMasterChefBOOV2 | SpookySwapSpellV2 |
SpiritSwap | WMasterChefSpiritV1 | SpiritSwapSpellV1 |
Beethoven | WMasterChefBeetsWorker | BeetsSpellV1 |
- make sure you have installed Foundry
- compile project
forge build
- run tests
forge test --contracts tests/ftm -vv --fork-url <FTM_RPC_URL> --via-ir