Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infra arthera adpools #423

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jspm_packages/
conf/wallets/bep20.json
conf/wallets/campaign.json
conf/wallets/campaign.polygon.json
conf/wallets/campaign.arthera.json
conf/ssl/fullchain.pem
conf/ssl/privkey.pem
conf/satt-token-firebase-adminsdk-fwxcj-2215bda3fa.json
Expand Down
2 changes: 2 additions & 0 deletions conf/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -5817,6 +5817,7 @@ PolygonConstants.oracle.address = process.env.CONST_ORACLE_ADDRESS_POLYGON

BttConstants.token.satt = process.env.CONST_TOKEN_SATT_BTT_ADDRESS
BttConstants.campaign.address = process.env.CONST_CAMPAIGN_ADDRESS_BTT
ArtheraConstants.campaign.address = process.env.CONST_CAMPAIGN_ADDRESS_ARTHERA
BttConstants.oracle.address = process.env.CONST_ORACLE_ADDRESS_BTT
TronConstant.token.satt = process.env.CONST_TOKEN_SATT_TRON_ADDRESS
TronConstant.campaign.address = process.env.CONST_CAMPAIGN_ADDRESS_TRON
Expand All @@ -5829,6 +5830,7 @@ Constants.token.native = process.env.TOKEN_NATIVE_CONTRACT
wrapConstants[Bep20NetworkConstant].address = process.env.CONST_WBNB
wrapConstants[PolygonNetworkConstant].address = process.env.CONST_WMATIC
wrapConstants[BttNetworkConstant].address = process.env.CONST_WBTT
wrapConstants[ArtheraNetworkConstant].address = process.env.CONST_WAA
wrapConstants[TronNetworkConstant] = { address: TronConstant.token.wtrx }

multicallConstants[Erc20NetworkConstant] = {
Expand Down
11 changes: 7 additions & 4 deletions controllers/campaign.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,25 @@ module.exports.launchCampaign = async (req, res) => {
await wrappedtrx(tronWeb, amount)
}
} else {
cred = await unlockV2(req, res)
cred =
network === 'ARTHERA'
? await unlockArthera(req, res)
: await unlockV2(req, res)

if (!cred) return
}

var ret = await createPerformanceCampaign(
dataUrl,
startDate,
endDate,
ratios,
tokenAddress === null ? Constants.token.native : tokenAddress,
tokenAddress,
amount,
cred,
tronWeb,
res,
limit
limit,
network
)
if (!ret) return
return responseHandler.makeResponseData(res, 200, 'success', ret)
Expand Down
1 change: 1 addition & 0 deletions middleware/campaignValidator.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const schemas = {
'polygon',
'tron',
'bttc',
'arthera',
]),
pass: Joi.string().required(),
ratios: Joi.array().required(),
Expand Down
73 changes: 61 additions & 12 deletions web3/campaigns.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
web3PolygonUrl,
CampaignConstants,
OracleConstants,
ArtheraNetworkConstant,
} = require('../conf/const')
const { Campaigns } = require('../model/index')

Expand Down Expand Up @@ -95,8 +96,14 @@ exports.unlockArthera = async (req, res) => {
let pass = req.body.pass
let account = await Wallet.findOne({ UserId })
let Web3ARTHERA = await artheraConnexion()
Web3ARTHERA.eth.accounts.wallet.decrypt([account.keystore], pass)
return { address: '0x' + account.keystore.address, Web3ARTHERA }
Web3ARTHERA.eth.accounts.wallet.decrypt(
[account.walletV2?.keystore],
pass
)
return {
address: '0x' + account.walletV2?.keystore.address,
Web3ARTHERA,
}
} catch (err) {
if (!!res && res.length > 0) {
res.status(500).send({
Expand Down Expand Up @@ -294,10 +301,16 @@ exports.unlockPolygon = async (req, res) => {
}

exports.lock = async (credentials) => {
credentials.Web3ETH.eth.accounts.wallet.remove(credentials.address)
credentials.Web3BEP20.eth.accounts.wallet.remove(credentials.address)
credentials.Web3POLYGON.eth.accounts.wallet.remove(credentials.address)
credentials.web3UrlBTT.eth.accounts.wallet.remove(credentials.address)
if (!!credentials.Web3ETH)
credentials.Web3ETH.eth.accounts.wallet.remove(credentials.address)
if (!!credentials.Web3BEP20)
credentials.Web3BEP20.eth.accounts.wallet.remove(credentials.address)
if (!!credentials.Web3POLYGON)
credentials.Web3POLYGON.eth.accounts.wallet.remove(credentials.address)
if (!!credentials.web3UrlBTT)
credentials.web3UrlBTT.eth.accounts.wallet.remove(credentials.address)
if (!!credentials.web3ARTHERA)
credentials.web3ARTHERA.eth.accounts.wallet.remove(credentials.address)
}
exports.lockNetwork = async (credentials) => {
credentials.web3.eth.accounts.wallet.remove(credentials.address)
Expand Down Expand Up @@ -382,7 +395,7 @@ exports.getAccount = async (req, res) => {
}

exports.isNativeAddr = (addr) => {
return addr == Constants.token.matic
return addr == Constants.token.matic || addr == null
}

exports.isWrappedAddr = (addr) => {
Expand All @@ -402,7 +415,8 @@ exports.createPerformanceCampaign = async (
credentials,
tronWeb,
res,
limit = 100
limit = 100,
network
) => {
try {
/** CHECK IF COMPAGNE NETWORK IS TRON */
Expand Down Expand Up @@ -452,16 +466,51 @@ exports.createPerformanceCampaign = async (

/** CHECK TOKEN IS NATIVE OR NO (BNB for BEP20 / ETH for ERC20 ) */
if (this.isNativeAddr(token)) {
token = wrapConstants[credentials.network].address
token =
network === 'ARTHERA'
? process.env.CONST_WAA
: wrapConstants[credentials.network].address
if (network === 'ARTHERA') {
tokenSmartContract = new credentials.Web3ARTHERA.eth.Contract(
wrapConstants[ArtheraNetworkConstant].abi,
wrapConstants[ArtheraNetworkConstant].address
)

let gasPrice = await credentials.Web3ARTHERA.eth.getGasPrice()
let gas = await tokenSmartContract.methods
.deposit()
.estimateGas({
from: credentials.address,
value: amount,
gasPrice,
})

await wrapNative(amount, credentials)
let receipt = await tokenSmartContract.methods
.deposit()
.send({
from: credentials.address,
value: amount,
gas,
gasPrice,
})
} else await wrapNative(amount, credentials)
}

/** GET CONTRACT */
const contract = await getContractByNetwork(credentials)
let contract

if (network === 'ARTHERA') {
contract = new credentials.Web3ARTHERA.eth.Contract(
CampaignConstants[ArtheraNetworkConstant].abi,
CampaignConstants[ArtheraNetworkConstant].address
)
} else contract = await getContractByNetwork(credentials)

/** GET GAS PRICE */
const gasPrice = await contract.getGasPrice()
const gasPrice =
network === 'ARTHERA'
? await credentials.Web3ARTHERA.eth.getGasPrice()
: await contract.getGasPrice()

/** GET GAS LIMIT FROM .env */
const gas = process.env.GAS_LIMIT
Expand Down
Loading