mirror of
https://github.com/status-im/snt-gas-relay.git
synced 2025-02-05 19:13:39 +00:00
Adding factor logic to relay
This commit is contained in:
parent
7bae020fa8
commit
2b3f01c355
@ -15,10 +15,24 @@
|
||||
"powTime": 1000
|
||||
},
|
||||
|
||||
"tokens": {
|
||||
"0x0": {
|
||||
"minRelayFactor": 1,
|
||||
"name": "Ethereum",
|
||||
"symbol": "ETH"
|
||||
},
|
||||
"0x0ABEEF": {
|
||||
"minRelayFactor": 1000000000000,
|
||||
"name": "RandomToken",
|
||||
"symbol": "RDN",
|
||||
"pricePlugin": "plugins/token-utils"
|
||||
}
|
||||
},
|
||||
|
||||
"contracts":{
|
||||
"IdentityGasRelay": {
|
||||
"isIdentity": true,
|
||||
"factoryAddress": "0x24cb6a5b6c81e8ce3edb059ab97984c3d3ea2e3e",
|
||||
"factoryAddress": "0x96f0811c6484c59c2674da1f64e725c01d82c1b5",
|
||||
"abiFile": "../abi/IdentityGasRelay.json",
|
||||
"allowedFunctions": [
|
||||
{
|
||||
@ -26,6 +40,7 @@
|
||||
"to": "_to",
|
||||
"value": "_value",
|
||||
"data": "_data",
|
||||
"gasPrice": "_gasPrice",
|
||||
"isToken": true,
|
||||
"token": "_baseToken"
|
||||
},
|
||||
@ -34,6 +49,7 @@
|
||||
"to": "_to",
|
||||
"value": "_value",
|
||||
"data": "_data",
|
||||
"gasPrice": "_gasPrice",
|
||||
"isToken": false
|
||||
}
|
||||
]
|
||||
|
15
app/gas-relayer/plugins/token-utils.js
Normal file
15
app/gas-relayer/plugins/token-utils.js
Normal file
@ -0,0 +1,15 @@
|
||||
class TokenUtils {
|
||||
constructor(tokenConfig){
|
||||
this.name = tokenConfig.name || "";
|
||||
this.symbol = tokenConfig.symbol || "";
|
||||
this.minRelayFactor = tokenConfig.minRelayFactor || 1;
|
||||
}
|
||||
|
||||
getFactor(){
|
||||
// TODO get price from somewhere
|
||||
return 100000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = TokenUtils;
|
@ -136,12 +136,34 @@ const processMessages = async function(error, message, subscription){
|
||||
return reply('Invalid contract code', message); // TODO Log this
|
||||
}
|
||||
|
||||
// Determining balances
|
||||
|
||||
const params = web3.eth.abi.decodeParameters(contract.allowedFunctions[functionName].inputs, functionParameters);
|
||||
const tokenAddress = contract.allowedFunctions[functionName].isToken ? params[contract.allowedFunctions[functionName].token] : "0x0";
|
||||
|
||||
// Determine if gas price offered is worth at least the minimum
|
||||
const gasPrice = params[contract.allowedFunctions[functionName].gasPrice];
|
||||
if(gasPrice < config.tokens[tokenAddress].minRelayFactor){
|
||||
return reply("_gasPrice less than minimum: ", config.tokens[tokenAddress.minRelayFactor]);
|
||||
}
|
||||
|
||||
// Obtain factor
|
||||
let factor;
|
||||
if(contract.allowedFunctions[functionName].isToken){
|
||||
const PricePlugin = require(config.tokens[tokenAddress].pricePlugin);
|
||||
const pricePlg = new PricePlugin(config.tokens)
|
||||
factor = pricePlg.getFactor();
|
||||
} else {
|
||||
factor = 1;
|
||||
}
|
||||
|
||||
console.log(factor);
|
||||
|
||||
/*
|
||||
// Determining balances
|
||||
let balance;
|
||||
if(contract.isIdentity){
|
||||
if(contract.allowedFunctions[functionName].isToken){
|
||||
const Token = new web3.eth.Contract(erc20ABI, params[contracts.allowedFunctions[functionName].token]);
|
||||
const Token = new web3.eth.Contract(erc20ABI, params[contract.allowedFunctions[functionName].token]);
|
||||
balance = new web3.utils.BN(await Token.methods.balanceOf(address).call());
|
||||
} else {
|
||||
balance = new web3.utils.BN(await web3.eth.getBalance(address));
|
||||
@ -149,14 +171,15 @@ const processMessages = async function(error, message, subscription){
|
||||
} else {
|
||||
// TODO SNT Controller
|
||||
}
|
||||
*/
|
||||
|
||||
// Estimating gas
|
||||
let estimatedGas = new web3.utils.BN(await web3.eth.estimateGas({
|
||||
to: address,
|
||||
data: params[contracts.allowedFunctions[functionName].data]
|
||||
}));
|
||||
|
||||
|
||||
// Estimating gas
|
||||
/*let estimatedGas = new web3.utils.BN(await web3.eth.estimateGas({
|
||||
to: address,
|
||||
data: params[contract.allowedFunctions[functionName].data]
|
||||
}));*/
|
||||
|
||||
// TODO determine if balance is enough
|
||||
|
||||
web3.eth.sendTransaction({
|
||||
|
Loading…
x
Reference in New Issue
Block a user