-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'polygon-prototype-staging' into 91-add-submit-button-fo…
…r-email-field-on-successful-and-unsuccessful-screen
- Loading branch information
Showing
41 changed files
with
603 additions
and
5,448 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
signer-service/src/api/controllers/subsidize.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const { Keypair } = require('stellar-sdk'); | ||
const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api'); | ||
const Big = require('big.js'); | ||
|
||
const { PENDULUM_WSS, PENDULUM_FUNDING_SEED } = require('../../constants/constants'); | ||
|
||
const { TOKEN_CONFIG } = require('../../constants/tokenConfig'); | ||
|
||
const TOKEN_TO_SWAP = 'usdc.axl'; | ||
|
||
exports.subsidizePreSwap = async (req, res) => { | ||
try { | ||
const { pendulumCurrencyId, maximumSubsidyAmountRaw } = TOKEN_CONFIG[TOKEN_TO_SWAP]; | ||
|
||
const { address, amountRaw } = req.body; | ||
console.log('Subsidize pre swap', address, amountRaw); | ||
|
||
if (Big(amountRaw).gt(Big(maximumSubsidyAmountRaw))) { | ||
throw new Error('Amount exceeds maximum subsidy amount'); | ||
} | ||
|
||
const keyring = new Keyring({ type: 'sr25519' }); | ||
const fundingAccountKeypair = keyring.addFromUri(PENDULUM_FUNDING_SEED); | ||
|
||
const wsProvider = new WsProvider(PENDULUM_WSS); | ||
const api = await ApiPromise.create({ provider: wsProvider }); | ||
await api.isReady; | ||
|
||
await api.tx.tokens.transfer(address, pendulumCurrencyId, amountRaw).signAndSend(fundingAccountKeypair); | ||
|
||
return res.status(200).json({ message: 'Subsidy transferred successfully' }); | ||
} catch (error) { | ||
console.error('Error in subsidizePreSwap::', error); | ||
return res.status(500).json({ error: 'Server error', details: error.message }); | ||
} | ||
}; | ||
|
||
exports.subsidizePostSwap = async (req, res) => { | ||
try { | ||
const { address, amountRaw, token } = req.body; | ||
console.log('Subsidize post swap', address, amountRaw, token); | ||
|
||
const { assetCode, assetIssuer, maximumSubsidyAmountRaw } = TOKEN_CONFIG[token]; | ||
|
||
if (Big(amountRaw).gt(Big(maximumSubsidyAmountRaw))) { | ||
throw new Error('Amount exceeds maximum subsidy amount'); | ||
} | ||
|
||
const assetIssuerHex = `0x${Keypair.fromPublicKey(assetIssuer).rawPublicKey().toString('hex')}`; | ||
const pendulumCurrencyId = { | ||
Stellar: { | ||
AlphaNum4: { code: assetCode.padEnd(4, '\0'), issuer: assetIssuerHex }, | ||
}, | ||
}; | ||
|
||
const keyring = new Keyring({ type: 'sr25519' }); | ||
const fundingAccountKeypair = keyring.addFromUri(PENDULUM_FUNDING_SEED); | ||
|
||
const wsProvider = new WsProvider(PENDULUM_WSS); | ||
const api = await ApiPromise.create({ provider: wsProvider }); | ||
await api.isReady; | ||
|
||
await api.tx.tokens.transfer(address, pendulumCurrencyId, amountRaw).signAndSend(fundingAccountKeypair); | ||
|
||
return res.status(200).json({ message: 'Subsidy transferred successfully' }); | ||
} catch (error) { | ||
console.error('Error in subsidizePreSwap::', error); | ||
return res.status(500).json({ error: 'Server error', details: error.message }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const express = require('express'); | ||
const controller = require('../../controllers/subsidize.controller'); | ||
const { | ||
validatePreSwapSubsidizationInput, | ||
validatePostSwapSubsidizationInput, | ||
} = require('../../middlewares/validators'); | ||
|
||
const router = express.Router({ mergeParams: true }); | ||
|
||
router.route('/preswap').post(validatePreSwapSubsidizationInput, controller.subsidizePreSwap); | ||
router.route('/postswap').post(validatePostSwapSubsidizationInput, controller.subsidizePostSwap); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
const HORIZON_URL = 'https://horizon.stellar.org'; | ||
//const HORIZON_URL = 'https://horizon-testnet.stellar.org'; | ||
const BASE_FEE = '1000000'; | ||
const PENDULUM_WSS = 'wss://rpc-pendulum.prd.pendulumchain.tech'; | ||
const NETWORK = 'Pendulum'; | ||
const FUNDING_AMOUNT_UNITS = '0.1'; | ||
const PENDULUM_FUNDING_SEED = 'issue hen firm river check income arrive illness pulse drop initial shrug'; | ||
require('dotenv').config(); | ||
|
||
module.exports = { BASE_FEE, HORIZON_URL, PENDULUM_WSS, NETWORK, FUNDING_AMOUNT_UNITS, PENDULUM_FUNDING_SEED }; | ||
const PENDULUM_FUNDING_SEED = process.env.PENDULUM_FUNDING_SEED; | ||
const FUNDING_SECRET = process.env.FUNDING_SECRET; | ||
|
||
module.exports = { BASE_FEE, HORIZON_URL, PENDULUM_WSS, NETWORK, FUNDING_AMOUNT_UNITS, PENDULUM_FUNDING_SEED, FUNDING_SECRET }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.