Routines Frontend Integration

Find All Routines Contracts

Routines Contracts are Factory-Based, which means that they are created by sending some directives to a Factory Smart Contract having a fixed address that can be found at the following links for mainnet and ropsten.

You can find all the needed ABIS here.

var deployEvent = "FixedInflationDeployed(address,address,bytes)";

var fixedInflationFactoryAddress = "0x285427916a9d2e991039A8F1611F575D0a6cf237";

var fixedInflationFactory = new web3.eth.Contract(abis.FixedInflationFactoryABI, fixedInflationFactoryAddress);

var logs = await web3.eth.getPastLogs({
    address : fixedInflationFactoryAddress,
    topics : [
        web3.util.sha3(deployEvent)
    ],
    fromBlock : '11882329',
    toBlock : 'latest'
});

var allFixedInflationContracts = logs.map(log => web3.eth.abi.decodeParameters("address", log.topics[1]));

Create a Simple Fixed Inflation Contract

var entry = {
    name : "My Awesome Daily Fixed Inflation",
    blockInterval : 6400,
    lastBlock : 0, //populate with a block number to a delayed start,
    callerRewardPercentage : 0.02 * 1e18 //a percentage (between 0 and 1 * 1e18) which will be the reward for the execution caller, in order to receive refunds for gas fees
};

//first operation is a buidl - ETH swap on Uniswap, to be sent to two different addresses
//second operation is a ETH transfer, to be sent to a unique address
var operations = [{
    inputTokenAddress : "0x7b123f53421b1bf8533339bfbdc7c98aa94163db",
    inputTokenAmount : 50 * 1e18,
    inputTokenAmountIsPercentage : false, //true means that inputTokenAmount is a percentage (between 0 and 1 * 1e18) of the entire token total supply. false means inputTokenAmount is just a simple amount
    inputTokenAmountIsByMint : false, //true means that extension will mint the inputTokenAmount (percentage or fixed numbers) of this token (make of course sure that Extension or its delegates have persmissions to do that). false is a simple transfer of already existing tokens
    
    ammPlugin : "0xFC1665BD717dB247CDFB3a08b1d496D1588a6340", //ammPlugin can be also address(0), which means that this operation is a simple transfer to several wallets
    liquidityPoolAddresses : ["0xb0fB35Cc576034b01bED6f4D0333b1bd3859615C"], //all the liquidity pool token addresses involved in this swap. Must be empty array if ammPlugin is address(0)
    swapPath : ["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"], //all the swap hops (must be tokens included in the liquidityPool token address at the same array position). Must be empty array if ammPlugin is address(0)
    enterInETH : false,
    exitInETH : true, //in this specific case (amm is UniswapV2), true means swap buidl-ETH, false means swap buidl-WETH
    
    receivers : [myAddress, otherAddress],// receivers of the swap output, there must be at least an address
    receiversPercentage : [0.4 * 1e18] //receiversPercentages length must be always receivers.length - 1. In this case, means that myAddress will receive the 40% of the swap output, while otherAddress the 60%. These percentages is calculated subtracting the eventual reward for the caller
}, 
{
    inputTokenAddress : "0x0000000000000000000000000000000000000000",
    inputTokenAmount : 0.05 * 1e18,
    inputTokenAmountIsPercentage : false, //true means that inputTokenAmount is a percentage (between 0 and 1 * 1e18) of the entire token total supply. false means inputTokenAmount is just a simple amount
    inputTokenAmountIsByMint : false, //true means that extension will mint the inputTokenAmount (percentage or fixed numbers) of this token (make of course sure that Extension or its delegates have persmissions to do that). false is a simple transfer of already existing tokens
    
    ammPlugin : "0x0000000000000000000000000000000000000000", //ammPlugin can be also address(0), which means that this operation is a simple transfer to several wallets
    liquidityPoolAddresses : [], //all the liquidity pool token addresses involved in this swap. Must be empty array if ammPlugin is address(0)
    swapPath : [], //all the swap hops (must be tokens included in the liquidityPool token address at the same array position). Must be empty array if ammPlugin is address(0)
    enterInETH : false,
    exitInETH : false, //in this specific case (amm is UniswapV2), true means swap buidl-ETH, false means swap buidl-WETH
    
    receivers : [otherAddress],// receivers of the swap output, there must be at least an address
    receiversPercentage : [] //receiversPercentages length must be always receivers.length - 1. In this case, means that otherAddress will receive the 100% of the transferred ETH. The percentage is calculated subtracting the eventual reward for the caller
}];

var transaction = await fixedInflationFactory.methods.cloneFixedInflationDefaultExtension().send();
var receipt = await web3.eth.getTransactionReceipt(transaction.transactionHash);
var log = receipt.logs.filter(log => log.topics[0] === web3.utils.sha3("ExtensionCloned(address)"))[0];
var extensionAddress = web3.eth.abi.decodeParameter("address", log.topics[1]);

var defaultExtension = new web3.eth.Contract(abis.FixedInflationExtensionABI, extensionAddress);

var extensionInitPayload = defaultExtension.methods.init(
    myWallet, //host
).encodeABI();

var fixedInflationTemplate = new web3.eth.Contract(abis.FixedInflationABI);

var initPayload = fixedInflationTemplate.methods.init(
    extensionAddress,
    extensionInitPayload,
    entry,
    operations
).encodeABI();

transaction = await fixedInflationFactory.methods.deploy(initPayload).send();
receipt = await web3.eth.getTransactionReceipt(transaction.transactionHash);
log = receipt.logs.filter(log => log.topics[0] === web3.utils.sha3("FixedInflationDeployed(address,address,bytes)"))[0];
var farmMainAddress = web3.eth.abi.decodeParameter("address", log.topics[1]);

Last updated