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

fix: fixing GMP #298

Merged
merged 6 commits into from
Sep 19, 2023
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
2 changes: 1 addition & 1 deletion packages/sdk/src/chains/EVM/__test__/depositFns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('deposit functions', () => {
'resourceId',
'depositData',
'feeData',
{ gasLimit: EVM.ASSET_TRANSFER_GAS_LIMIT },
{ gasLimit: EVM.ASSET_TRANSFER_GAS_LIMIT, value: BigNumber.from(100) },
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/chains/EVM/__test__/dynamicFee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jest.mock(
() =>
({
...jest.requireActual('@buildwithsygma/sygma-contracts'),
DynamicERC20FeeHandlerEVM__factory: {
FeeHandlerRouter__factory: {
connect: () => {
return {
calculateFee: jest.fn(() =>
Expand Down
24 changes: 12 additions & 12 deletions packages/sdk/src/chains/EVM/fee/dynamicFee.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DynamicERC20FeeHandlerEVM__factory } from '@buildwithsygma/sygma-contracts';
import { FeeHandlerRouter__factory } from '@buildwithsygma/sygma-contracts';
import { ethers } from 'ethers';
import fetch from 'cross-fetch';

Expand All @@ -19,7 +19,7 @@ type OracleResponse = {
* @param {string} amount - Amount in string format.
* @returns {string} - Returns the oracleMessage, signature and amount.
*/
export const createOracleFeeData = (oracleResponse: OracleResource, amount?: string): string => {
export const createOracleFeeData = (oracleResponse: OracleResource, amount: string): string => {
/*
feeData structure:
ber*10^18: uint256
Expand Down Expand Up @@ -57,11 +57,8 @@ export const createOracleFeeData = (oracleResponse: OracleResource, amount?: str
);

const signature = oracleResponse.signature;
if (amount) {
return oracleMessage + signature + toHex(amount, 32).substring(2);
} else {
return oracleMessage + signature;
}

return oracleMessage + signature + toHex(amount, 32).substring(2);
};

/**
Expand Down Expand Up @@ -115,6 +112,7 @@ export const calculateDynamicFee = async ({
feeHandlerAddress,
depositData,
tokenAmount,
maxFee,
}: {
provider: ethers.providers.Provider;
sender: string;
Expand All @@ -124,16 +122,18 @@ export const calculateDynamicFee = async ({
feeOracleBaseUrl: string;
feeHandlerAddress: string;
depositData: string;
tokenAmount?: string;
tokenAmount: string;
maxFee?: string;
}): Promise<EvmFee> => {
const oracleResponse = await requestFeeFromFeeOracle({
feeOracleBaseUrl,
fromDomainID,
toDomainID,
resourceID,
msgGasLimit: maxFee,
});
const feeData = createOracleFeeData(oracleResponse, tokenAmount);
const FeeHandlerWithOracleInstance = DynamicERC20FeeHandlerEVM__factory.connect(
const FeeHandlerWithOracleInstance = FeeHandlerRouter__factory.connect(
feeHandlerAddress,
provider,
);
Expand Down Expand Up @@ -172,16 +172,16 @@ export const requestFeeFromFeeOracle = async ({
fromDomainID,
toDomainID,
resourceID,
msgGasLimit = 0,
msgGasLimit = '0',
}: {
feeOracleBaseUrl: string;
fromDomainID: number;
toDomainID: number;
resourceID: string;
msgGasLimit?: number;
msgGasLimit?: string;
}): Promise<OracleResource> => {
const response = await fetch(
`${feeOracleBaseUrl}/v1/rate/from/${fromDomainID}/to/${toDomainID}/resourceid/${resourceID}?gasLimit=${msgGasLimit}`,
`${feeOracleBaseUrl}/v1/rate/from/${fromDomainID}/to/${toDomainID}/resourceid/${resourceID}?msgGasLimit=${msgGasLimit}`,
{
headers: {
'Cache-Control': 'no-cache',
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/chains/EVM/genericMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export class EVMGenericMessageTransfer {
transfer.sender,
genericTransfer.details.executionData,
),
tokenAmount: genericTransfer.details.tokenAmount,
maxFee: genericTransfer.details.maxFee,
});
}
default:
Expand Down Expand Up @@ -147,6 +149,7 @@ export class EVMGenericMessageTransfer {
destinationFunctionSignature: string,
executionData: string,
maxFee: string,
tokenAmount?: string,
): Transfer<GenericMessage> {
const { sourceDomain, destinationDomain, resource } = this.config.getBaseTransferParams(
destinationChainId,
Expand All @@ -160,6 +163,7 @@ export class EVMGenericMessageTransfer {
destinationFunctionSignature: destinationFunctionSignature,
executionData: executionData,
maxFee: maxFee,
tokenAmount: tokenAmount || '0',
},
from: sourceDomain,
to: destinationDomain,
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk/src/chains/EVM/utils/depositFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { BigNumber, ContractReceipt, PopulatedTransaction, ethers } from 'ethers
import { Bridge } from '@buildwithsygma/sygma-contracts';
import { DepositEvent } from '@buildwithsygma/sygma-contracts/dist/ethers/Bridge.js';

import { FeeHandlerType } from '../../../types/index.js';
import { createERCDepositData, createPermissionlessGenericDepositData } from '../helpers.js';
import { Erc20TransferParamsType, Erc721TransferParamsType, EvmFee } from '../types/index.js';

Expand Down Expand Up @@ -134,7 +133,7 @@ export const executeDeposit = async (
overrides?: ethers.PayableOverrides,
): Promise<PopulatedTransaction> => {
const transactionSettings = {
value: feeData.type === FeeHandlerType.BASIC ? feeData.fee : undefined,
value: feeData.fee,
gasLimit: ASSET_TRANSFER_GAS_LIMIT,
};

Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type GenericMessage = {
destinationFunctionSignature: string;
executionData: string;
maxFee: string;
tokenAmount: string;
};

export type TransferType = Fungible | NonFungible | GenericMessage;
Expand Down
Loading