Skip to content

Commit

Permalink
Merge pull request #19 from sotatek-dev/feat/refactor
Browse files Browse the repository at this point in the history
fix: add base fee mina bridge
  • Loading branch information
Sotatek-TanHoang authored Jun 11, 2024
2 parents 82772e7 + b0614e4 commit 8f521f8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ ETH_BRIDGE_RPC_OPTIONS=https://ethereum-sepolia.publicnode.com
MINA_BRIDGE_START_BLOCK=0
MINA_BRIDGE_CONTRACT_ADDRESS=B62qkttesK1uAJU5iL8vqcfyoHX8KqVVAiK6VUWvro9EafSACYdZHbg
MINA_TOKEN_BRIDGE_ADDRESS=B62qrAATNLCVXtXrkN43q9XXgLKo9okhsHDqLy6xhd7MJD2nZnN7Z4r
MINA_BRIDGE_RPC_OPTIONS=https://api.minascan.io/node/berkeley/v1/graphql
MINA_BRIDGE_RPC_OPTIONS=https://proxy.devnet.minaexplorer.com/graphql
MINA_BRIDGE_ARCHIVE_RPC_OPTIONS=https://api.minascan.io/archive/devnet/v1/graphql/

SIGNER_PRIVATE_KEY=9b603dddc852f944a329501ae81b9e1c6f1dcdeabbdcfea8df4c20c515a30fa8
SIGNER_MINA_PRIVATE_KEY=EKEuMcfaRFhtoXUr4gAFxYSS5oKWVuiYvUYRQBcaJ19focCmn4XL
Expand Down
3 changes: 3 additions & 0 deletions src/config/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ import redisConfig from './redis.config';
// coinmarketcap
[EEnvKey.COINMARKET_KEY]: Joi.string().required(),
[EEnvKey.COINMARKET_URL]: Joi.string().required(),

// fee
[EEnvKey.BASE_MINA_BRIDGE_FEE]: Joi.number().default(1 * Math.pow(10, 8)),
}).custom(value => {
value[EEnvKey.ETH_BRIDGE_START_BLOCK] = isNumber(value[EEnvKey.ETH_BRIDGE_START_BLOCK])
? value[EEnvKey.ETH_BRIDGE_START_BLOCK]
Expand Down
1 change: 1 addition & 0 deletions src/constants/env.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ export enum EEnvKey {
DECIMAL_TOKEN_MINA = 'DECIMAL_TOKEN_MINA',
COINMARKET_KEY = 'COINMARKET_KEY',
COINMARKET_URL = 'COINMARKET_URL',
BASE_MINA_BRIDGE_FEE = 'BASE_MINA_BRIDGE_FEE',
}
6 changes: 4 additions & 2 deletions src/modules/crawler/sender.minabridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ export class SenderMinaBridge {
Mina.setActiveInstance(network);

this.logger.info('compile the contract...');

await Bridge.compile();
await FungibleToken.compile();
const fee = 1 * Math.pow(10, 9);
// const fee = protocolFeeAmount * rateMINAETH + 5 * Math.pow(10, 8); // in nanomina (1 billion = 1.0 mina)

const fee = protocolFeeAmount * rateMINAETH + +this.configService.get(EEnvKey.BASE_MINA_BRIDGE_FEE); // in nanomina (1 billion = 1.0 mina)
const feepayerAddress = feepayerKey.toPublicKey();
const zkAppAddress = zkAppKey.toPublicKey();
const zkBridge = new Bridge(zkAppAddress);

await fetchAccount({ publicKey: zkAppAddress });
await fetchAccount({ publicKey: feepayerAddress });

Expand Down
5 changes: 3 additions & 2 deletions src/modules/crawler/tests/mina-sender.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TokenPriceRepository } from 'database/repositories/token-price.reposito

import { ConfigurationModule } from '@config/config.module';

import { LoggingModule } from '@shared/modules/logger/logger.module';
import { Web3Module } from '@shared/modules/web3/web3.module';

import { SenderMinaBridge } from '../sender.minabridge';
Expand Down Expand Up @@ -37,7 +38,7 @@ describe('AuthService', () => {

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [Web3Module, ConfigurationModule],
imports: [Web3Module, ConfigurationModule, LoggingModule],
providers: [
SenderMinaBridge,
{ provide: JwtService, useValue: mockJwtService },
Expand All @@ -57,7 +58,7 @@ describe('AuthService', () => {
id: 333,
tokenReceivedAddress: 'B62qqki2ZnVzaNsGaTDAP6wJYCth5UAcY6tPX2TQYHdwD8D4uBgrDKC',
tokenFromAddress: '0x0000000000000000000000000000000000000000',
receiveAddress: 'B62qqki2ZnVzaNsGaTDAP6wJYCth5UAcY6tPX2TQYHdwD8D4uBgrDKC',
receiveAddress: 'B62qjWwgHupW7k7fcTbb2Kszp4RPYBWYdL4KMmoqfkMH3iRN2FN8u5n',
amountFrom: '15690000000000000',
senderAddress: '0xb3Edf83eA590F44f5c400077EBd94CCFE10E4Bb0',
});
Expand Down

0 comments on commit 8f521f8

Please sign in to comment.