Skip to content

Instantly share code, notes, and snippets.

@bonedaddy
Last active May 3, 2022 09:21
Show Gist options
  • Save bonedaddy/63fe0fdd2c991a48defe392bae4cbeb2 to your computer and use it in GitHub Desktop.
Save bonedaddy/63fe0fdd2c991a48defe392bae4cbeb2 to your computer and use it in GitHub Desktop.
Bastion Reward Claiming Ooptimization

Optimized Bastion Reward Claiming - Reduce Txns/Costs By ~75%

I accept no responsibility for loss of funds, or any perceived negative consequences that happens as a result of this code. It has not been audited use at your own risk

Due to the way Aurora works, each contract can only burn a certain amount of gas. Because of this we need to be able to optimize the way to send transactions. Using the following it's possible to claim all liquidity mining rewards from all realms in three transactions. Using this method you can send a max of 3 transactions, as opposed to the 8 that would be required harvesting rewards individually. This does not claim staking rewards given out by the kingdom.

Assuming a cost of 6 cents per transaction, using this method will save you approximately 30 cents in gas fees, allowing for quicker ROI when farming bastion.

Contract Code

If you wish there is one deployed to 0xdedde17601aa03168ba68ade9171f6b6e2218b8c

pragma solidity 0.8.13;

interface BastionClaimerI {
    function claimReward(uint8 rewardType, address holder, address[] memory cTokens) external;
} 
 
contract BasedMultiClaimer {

    // feeling generous? 0x1435dD42EF6d65B882136A8d12e88e968eC2b6c9
    struct RewardClaim {
        address[] cTokens;
        address distributorContract;
    }
    
    function batchClaimReward(
        RewardClaim[] calldata rewardClaims,
        uint  minRewardType,
        uint maxRewardType
    ) payable external  {
        unchecked {
            uint claimsLength = rewardClaims.length;

            for (uint i = 0; i < claimsLength; ++i) {

                address distributorContract = rewardClaims[i].distributorContract;
                address[] memory cTokens = rewardClaims[i].cTokens;
                for (uint ii = minRewardType; ii < maxRewardType; ++ii) {
                    uint8 rtype = uint8(ii);
                    BastionClaimerI(distributorContract).claimReward(
                        rtype,
                        msg.sender,
                        cTokens
                    );
                }
                delete cTokens;
                delete distributorContract;

            }
            delete claimsLength;
        }

    }
}

Transactions

The way of submitting reward claim transaction is fairly simple. You just provide the array of accounts used, as well as the max reward types number to iterate though. It's recommended to batch together claims of the same reward types across the different realms.

Txn 1

The following arguments when provided to the smart contract will claim the first "first" reward from the Multi, Aurora, and Staked realms. This is usually BSTN, but for the staked near pool it will be NEAR.

multi -> aurora -> staked

min: 0, max: 1, accounts:

[[["0x10a9153A7b4da83Aa1056908C710f1aaCCB3Ef85", "0x30Fff4663A8DCDd9eD81e60acF505e6159f19BbC"],"0xeCa5553ed50cF52aa34c1F9242aEcfD1e7A7667F"],[["0x94FA9979751a74e6b133Eb95Aeca8565c0809BaB", "0x8E9FB3f2cc8b08184CB5FB7BcDC61188E80C3cB0", "0x86538Ca055E7Fd992A26c5604F349e2ede3ce42D"],"0xF9C3a8cF63154A5bD1a87b6f49575d47b7F713Bd"],[["0x4A45075D3E752F3676610Fc427F5E6915Ce63A63", "0xB76108eb764b4427505c4bb020A37D95b3ef5AFE"],"0xd7A812a5d2CC96e78C83B0324c82269EE82aF1c8"]]

Txn 2

The following arguments when provided to the smart contract will claim the "second" reward from the Multi, Aurora, and Staked realms. This is usually NEAR but for the staked near pool it will be META

multi -> aurora -> staked

min: 1, max: 2, accounts:

[[["0x10a9153A7b4da83Aa1056908C710f1aaCCB3Ef85", "0x30Fff4663A8DCDd9eD81e60acF505e6159f19BbC"],"0xeCa5553ed50cF52aa34c1F9242aEcfD1e7A7667F"],[["0x94FA9979751a74e6b133Eb95Aeca8565c0809BaB", "0x8E9FB3f2cc8b08184CB5FB7BcDC61188E80C3cB0", "0x86538Ca055E7Fd992A26c5604F349e2ede3ce42D"],"0xF9C3a8cF63154A5bD1a87b6f49575d47b7F713Bd"],[["0x4A45075D3E752F3676610Fc427F5E6915Ce63A63", "0xB76108eb764b4427505c4bb020A37D95b3ef5AFE"],"0xd7A812a5d2CC96e78C83B0324c82269EE82aF1c8"]]

Txn 3

The final set of arguments will be used to claim all rewards from the main hub pool. min: 0, max: 2, accounts:

[[["0xfa786baC375D8806185555149235AcDb182C033b", "0x4E8fE8fd314cFC09BDb0942c5adCC37431abDCD0", "0x8C14ea853321028a7bb5E4FB0d0147F183d3B677", "0xe5308dc623101508952948b141fD9eaBd3337D99", "0x845E15A441CFC1871B7AC610b0E922019BaD9826"],"0x98E8d4b4F53FA2a2d1b9C651AF919Fc839eE4c1a"],[["0xfa786baC375D8806185555149235AcDb182C033b", "0x4E8fE8fd314cFC09BDb0942c5adCC37431abDCD0", "0x8C14ea853321028a7bb5E4FB0d0147F183d3B677", "0xe5308dc623101508952948b141fD9eaBd3337D99", "0x845E15A441CFC1871B7AC610b0E922019BaD9826"],"0x98E8d4b4F53FA2a2d1b9C651AF919Fc839eE4c1a"]]

groupings

staked near

[[["0x4A45075D3E752F3676610Fc427F5E6915Ce63A63", "0xB76108eb764b4427505c4bb020A37D95b3ef5AFE"],"0xd7A812a5d2CC96e78C83B0324c82269EE82aF1c8"]]

main hub

[[["0xfa786baC375D8806185555149235AcDb182C033b", "0x4E8fE8fd314cFC09BDb0942c5adCC37431abDCD0", "0x8C14ea853321028a7bb5E4FB0d0147F183d3B677", "0xe5308dc623101508952948b141fD9eaBd3337D99", "0x845E15A441CFC1871B7AC610b0E922019BaD9826"],"0x98E8d4b4F53FA2a2d1b9C651AF919Fc839eE4c1a"],[["0xfa786baC375D8806185555149235AcDb182C033b", "0x4E8fE8fd314cFC09BDb0942c5adCC37431abDCD0", "0x8C14ea853321028a7bb5E4FB0d0147F183d3B677", "0xe5308dc623101508952948b141fD9eaBd3337D99", "0x845E15A441CFC1871B7AC610b0E922019BaD9826"],"0x98E8d4b4F53FA2a2d1b9C651AF919Fc839eE4c1a"]]

aurora (kingdom staking rewards)

[[["0x94FA9979751a74e6b133Eb95Aeca8565c0809BaB","0x8E9FB3f2cc8b08184CB5FB7BcDC61188E80C3cB0","0x86538Ca055E7Fd992A26c5604F349e2ede3ce42D","0x08Ac1236ae3982EC9463EfE10F0F320d9F5A9A4b"], "0xF9C3a8cF63154A5bD1a87b6f49575d47b7F713Bd"]]

aurora

[[["0x94FA9979751a74e6b133Eb95Aeca8565c0809BaB", "0x8E9FB3f2cc8b08184CB5FB7BcDC61188E80C3cB0", "0x86538Ca055E7Fd992A26c5604F349e2ede3ce42D"], "0xF9C3a8cF63154A5bD1a87b6f49575d47b7F713Bd"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment