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.
There are many types of wrapper contracts that support pools on traderJoe depending on TraderJoe's reward contract. Although, the method of calculating pending rewards may be different for each wrapper, we can use same spell interface. See Appendix A to know which pool use which wrapper contract.
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 on WMasterChefJoeV2
parameters | description |
---|---|
pid | pool id in TraderJoe's masterchefV2 |
rewardPerShare | latest-updated accumulated reward per share (being used for calculating pending reward) |
IBankAVAX bank = IBankAVAX(0x376d16C7dE138B01455a51dA79AD65806E9cd694);
uint256 positionId = 123; // change position id here
(
,
address collateralTokenAddress,
uint256 collateralId,
uint256 collateralAmount
) = bank.getPositionInfo(positionId);
IWMasterChefJoeV2 wrapper = IWMasterChefJoeV2(collateralTokenAddress);
(uint256 pid, uint256 rewardPerShare) = wrapper.decodeId(
collateralId
);
Decoding wrapper token ID on WMasterChefJoeV3
parameters | description |
---|---|
pid | pool id in TraderJoe's masterchefV3 |
rewardPerShare | latest-updated accumulated reward per share (being used for calculating pending reward) |
IBankAVAX bank = IBankAVAX(0x376d16C7dE138B01455a51dA79AD65806E9cd694);
uint256 positionId = 123; // change position id here
(
,
address collateralTokenAddress,
uint256 collateralId,
uint256 collateralAmount
) = bank.getPositionInfo(positionId);
IWMasterChefJoeV3 wrapper = IWMasterChefJoeV3(collateralTokenAddress);
(uint256 pid, uint256 rewardPerShare) = wrapper.decodeId(
collateralId
);
Decoding wrapper token ID on WBoostedMasterChefJoeV3
parameters | description |
---|---|
pid | pool id in TraderJoe's boosted masterchefV3 |
rewardPerShare | latest-updated accumulated reward per share (being used for calculating pending reward) |
IBankAVAX bank = IBankAVAX(0x376d16C7dE138B01455a51dA79AD65806E9cd694);
uint256 positionId = 123; // change position id here
(
,
address collateralTokenAddress,
uint256 collateralId,
uint256 collateralAmount
) = bank.getPositionInfo(positionId);
IWBoostedMasterChefJoeWorker wrapper = IWBoostedMasterChefJoeWorker(collateralTokenAddress);
(uint256 pid, uint256 rewardPerShare) = wrapper.decodeId(
collateralId
);
Spell Address: See Appendix A
Example of how to integrate with Homora here
Functions:
- addLiquidityWMiniChef: Leverage, provide liquidity to the pool and stake LP to the staking contract.
- removeLiquidityWMiniChef: unstake LP, remove liquidity from the pool and repay a loan.
- harvestWMiniChefRewards: collect minichef rewards.
Decoding wrapper token ID on WMiniChefV2PNG
parameters | description |
---|---|
pid | pool id in Pangolin's minichef |
rewardPerShare | latest-updated accumulated reward per share (being used for calculating pending reward) |
IBankAVAX bank = IBankAVAX(0x376d16C7dE138B01455a51dA79AD65806E9cd694);
uint256 positionId = 123; // change position id here
(
,
address collateralTokenAddress,
uint256 collateralId,
uint256 collateralAmount
) = bank.getPositionInfo(positionId);
IWMiniChefV2PNG wrapper = IWMiniChefV2PNG(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 | Wrapper contracts | Spell contracts |
---|---|---|
TraderJoe pools: WAVAX-DAI.e, USDC.e-USDT.e, USDC.e-DAI.e |
WMasterchefJoeV2 | TraderJoeSpellV1 |
TraderJoe pools: ALPHA.e-WAVAX |
WMasterchefJoeV3 | TraderJoeSpellV2 |
TraderJoe pools: WAVAX-USDC, WETH.e-WAVAX, USDT.e-WAVAX, USDC.e-WAVAX, MIM-WAVAX, WBTC.e-WAVAX, USDC-USDC.e, LINK.e-WAVAX |
WBoostedMasterchefJoeV3 | TraderJoeSpellV3 |
every pool in Pangolin Exchange |
WMiniChefV2PNG | PangolinSpellV2 |
- make sure you have installed Foundry
- compile project
forge build
- run tests
forge test --contracts tests/avax -vv --fork-url <AVAX_RPC_URL> --via-ir