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:
- addLiquidityWERC20: Leverage & provide liquidity to the pool.
- addLiquidityWStakingRewards: Leverage, provide liquidity to the pool and stake LP to the staking contract.
- removeLiquidityWERC20: remove liquidity from the pool and repay a loan.
- removeLiquidityWStakingRewards: unstake LP, remove liquidity from the pool and repay a loan.
- harvestWStakingRewards: collect staking rewards.
Decoding wrapper token ID
parameters | description |
---|---|
rewardPerShare | latest-updated accumulated reward per share (being used for calculating pending reward) |
IBankETH bank = IBankETH(0xba5eBAf3fc1Fcca67147050Bf80462393814E54B);
uint256 positionId = 123; // change position id here
(
,
address collateralTokenAddress,
uint256 collateralId,
uint256 collateralAmount
) = bank.getPositionInfo(positionId);
uint256 rewardPerShare = collateralId;
Spell Address: See Appendix A
Example of how to integrate with Homora here
Functions:
- addLiquidityWERC20: Leverage & provide liquidity to the pool.
- addLiquidityWMasterChef: Leverage, provide liquidity to the pool and stake LP to the staking contract.
- removeLiquidityWERC20: remove liquidity from the pool and repay a loan.
- 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 Sushiswap's masterchef |
rewardPerShare | latest-updated accumulated reward per share (being used for calculating pending reward) |
IBankETH bank = IBankETH(0xba5eBAf3fc1Fcca67147050Bf80462393814E54B);
uint256 positionId = 123; // change position id here
(
,
address collateralTokenAddress,
uint256 collateralId,
uint256 collateralAmount
) = bank.getPositionInfo(positionId);
IWMasterChef wrapper = IWMasterChef(collateralTokenAddress);
(uint256 pid, uint256 rewardPerShare) = wrapper.decodeId(
collateralId
);
Spell Address: 0x8b947D8448CFFb89EF07A6922b74fBAbac219795
Example of how to integrate with Homora here
Functions:
- addLiquidity3: Leverage, provide liquidity to the pool and staking to the gauge contract.
- removeLiquidity3: unstake LP, remove liquidity from the pool and repay a loan.
- harvest: collect gauge rewards.
Decoding wrapper token ID
parameters | description |
---|---|
pid | pool id in Curve's gauge (refer to lp token) |
gid | gauge id in Curve's gauge (refer to gauge reward) |
rewardPerShare | latest-updated accumulated reward per share (being used for calculating pending reward) |
IBankETH bank = IBankETH(0xba5eBAf3fc1Fcca67147050Bf80462393814E54B);
uint256 positionId = 123; // change position id here
(
,
address collateralTokenAddress,
uint256 collateralId,
uint256 collateralAmount
) = bank.getPositionInfo(positionId);
IWLiquidityGauge wrapper = IWLiquidityGauge(collateralTokenAddress);
(uint256 pid, uint256 gid, uint256 rewardPerShare) = wrapper.decodeId(
collateralId
);
Name | Contract address |
---|---|
HomoraBank | 0xba5eBAf3fc1Fcca67147050Bf80462393814E54B |
UniswapV2SpellV1 | 0x00b1a4E7F217380a7C9e6c12F327AC4a1D9B6A14 |
SushiswapSpellV1 | 0xDc9c7A2Bae15dD89271ae5701a6f4DB147BAa44C |
CurveSpellV1 | 0x8b947D8448CFFb89EF07A6922b74fBAbac219795 |
WERC20 | 0x06799a1e4792001AA9114F0012b9650cA28059a3 |
WStakingRewards (INDEX) | 0x011535FD795fD28c749363E080662D62fBB456a7 |
WMasterChef | 0xA2caEa05fF7B98f10Ad5ddc837F15905f33FEb60 |
WLiquidityGauge | 0xf1F32C8EEb06046d3cc3157B8F9f72B09D84ee5b |
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 |
---|---|---|
every pool in UniswapV2 (no reward) |
WERC20 | UniswapSpellV1 |
every pool in UniswapV2 (INDEX) |
WStakingRewards | UniswapSpellV1 |
every pool in Sushiswap (no reward) |
WERC20 | SushiswapSpellV1 |
every pool in Sushiswap | WMasterChef | SushiswapSpellV1 |
every pools in Curve | WLiquidityGauge | CurveSpellV1 |
- make sure you have installed Foundry
- compile project
forge build
- run tests
forge test --contracts tests/eth -vv --fork-url <ETH_RPC_URL> --via-ir