Skip to content

Commit

Permalink
MEX-397: add query for increase proxy pair token energy transaction
Browse files Browse the repository at this point in the history
Signed-off-by: Claudiu Lataretu <[email protected]>
  • Loading branch information
claudiulataretu committed Oct 30, 2023
1 parent 63b24e4 commit f9d849b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@
"withTokenMerge": 40000000
},
"removeLiquidity": 30000000,
"defaultMergeWLPT": 20000000
"defaultMergeWLPT": 20000000,
"increaseEnergy": 20000000
},
"farms": {
"v1.2": {
Expand Down
2 changes: 2 additions & 0 deletions src/modules/proxy/proxy.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ProxyQueryResolver } from './proxy.query.resolver';
import { ProxyResolver } from './proxy.resolver';
import { WrappedLpTokenAttributesResolverV2 } from './wrappedLp.token.v2.resolver';
import { WrappedFarmTokenResolverV2 } from './wrappedFarm.token.v2.resolver';
import { EnergyModule } from '../energy/energy.module';

@Module({
imports: [
Expand All @@ -27,6 +28,7 @@ import { WrappedFarmTokenResolverV2 } from './wrappedFarm.token.v2.resolver';
forwardRef(() => ProxyFarmModule),
forwardRef(() => ProxyModuleV2),
FarmModule,
EnergyModule,
],
providers: [
ProxyAbiService,
Expand Down
44 changes: 44 additions & 0 deletions src/modules/proxy/proxy.transaction.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ import { InputTokenModel } from 'src/models/inputToken.model';
import { LiquidityTokensValidationPipe } from './validators/add.liquidity.input.validator';
import { ProxyService } from './services/proxy.service';
import { scAddress } from 'src/config';
import { GraphQLError } from 'graphql';
import { ApolloServerErrorCode } from '@apollo/server/errors';
import { EnergyAbiService } from '../energy/services/energy.abi.service';

@Resolver()
export class ProxyTransactionResolver {
constructor(
private readonly proxyService: ProxyService,
private readonly energyAbi: EnergyAbiService,
private readonly transactionsProxyPairService: ProxyPairTransactionsService,
private readonly transactionsProxyFarmService: ProxyFarmTransactionsService,
) {}
Expand Down Expand Up @@ -195,4 +199,44 @@ export class ProxyTransactionResolver {
args,
);
}

@UseGuards(JwtOrNativeAuthGuard)
@Query(() => TransactionModel)
async increaseProxyPairTokenEnergy(
@Args('payment') payment: InputTokenModel,
@Args('lockEpochs') lockEpochs: number,
@AuthUser() user: UserAuthResult,
): Promise<TransactionModel> {
let proxyAddress: string;
try {
proxyAddress = await this.proxyService.getProxyAddressByToken(
payment.tokenID,
);

if (proxyAddress !== scAddress.proxyDexAddress.v2) {
throw new Error('Wrapped lp token is not supported');
}

const lockOptions = await this.energyAbi.lockOptions();
if (
lockOptions.find(
(option) => option.lockEpochs === lockEpochs,
) === undefined
) {
throw new Error('Invalid lock epochs!');
}
} catch (error) {
throw new GraphQLError(error.message, {
extensions: {
code: ApolloServerErrorCode.BAD_USER_INPUT,
},
});
}
return this.transactionsProxyPairService.increaseProxyPairTokenEnergy(
user.address,
proxyAddress,
payment,
lockEpochs,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
BigUIntValue,
BytesValue,
TypedValue,
U64Value,
} from '@multiversx/sdk-core/out/smartcontracts/typesystem';
import { Address, TokenTransfer } from '@multiversx/sdk-core';
import { TransactionModel } from 'src/models/transaction.model';
Expand Down Expand Up @@ -236,6 +237,33 @@ export class ProxyPairTransactionsService {
.toPlainObject();
}

async increaseProxyPairTokenEnergy(
sender: string,
proxyAddress: string,
payment: InputTokenModel,
lockEpochs: number,
): Promise<TransactionModel> {
const contract = await this.mxProxy.getProxyDexSmartContract(

Check warning on line 246 in src/modules/proxy/services/proxy-pair/proxy.pair.transactions.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/proxy/services/proxy-pair/proxy.pair.transactions.service.ts#L246

Added line #L246 was not covered by tests
proxyAddress,
);
return contract.methodsExplicit

Check warning on line 249 in src/modules/proxy/services/proxy-pair/proxy.pair.transactions.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/proxy/services/proxy-pair/proxy.pair.transactions.service.ts#L249

Added line #L249 was not covered by tests
.increaseProxyPairTokenEnergy([
new U64Value(new BigNumber(lockEpochs)),
])
.withSingleESDTNFTTransfer(
TokenTransfer.metaEsdtFromBigInteger(
payment.tokenID,
payment.nonce,
new BigNumber(payment.amount),
),
)
.withSender(Address.fromString(sender))
.withGasLimit(gasConfig.proxy.pairs.increaseEnergy)
.withChainID(mxConfig.chainID)
.buildTransaction()
.toPlainObject();
}

private async convertInputTokenstoESDTTokens(
tokens: InputTokenModel[],
): Promise<InputTokenModel[]> {
Expand Down

0 comments on commit f9d849b

Please sign in to comment.