Skip to content

Commit

Permalink
update: time & protocol fee estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mithreum committed Oct 22, 2024
1 parent cf06915 commit bb61743
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 45 deletions.
7 changes: 6 additions & 1 deletion src/chains/ton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
type GetLpFeeGrowthGlobal,
type GetLpProviderRewards,
type IsTransferFromLp,
type GetProtocolFeeInUSD,
type GetSwapResultAmount,
type GetCrossChainStrategy,
type SwapTokens,
Expand Down Expand Up @@ -88,6 +89,7 @@ export type TonHelper = GetBalance &
GetLpFeeDecimals &
IsTransferFromLp &
GetSwapResultAmount &
GetProtocolFeeInUSD &
// GetIncomingStrategy &
GetCrossChainStrategy &
SwapTokens<Sender, undefined>;
Expand Down Expand Up @@ -569,7 +571,7 @@ export async function tonHandler({
);
return address.toString();
},
estimateTime: () => Promise.resolve(undefined),
estimateTime: () => Promise.resolve(2n * 60n * 1000n), // 2 minutes
isTransferFromLp: () => Promise.resolve(false), // TODO: update it
async emmetHashFromtx(hash) {
const b64 = Buffer.from(hash, "hex").toString("base64");
Expand Down Expand Up @@ -657,6 +659,9 @@ export async function tonHandler({
const jw = fetchClient().open(JettonWallet.create(jwa));
return jw.getBalance();
},
protocolFeeInUSD: () => {
return 50n;
},
sendInstallment: async (
signer,
amt,
Expand Down
100 changes: 57 additions & 43 deletions src/chains/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,31 +219,38 @@ export async function web3Helper({
return amount;
},
async crossChainStrategy(targetChain, fromSymbol, targetSymbol) {
const ccts = await data.getStrategy(
targetChain,
fromSymbol,
targetSymbol,
);


const outgoing: TStrategy[] = [];
const incoming: TStrategy[] = [];
const foreign: TStrategy[] = [];

const map = [
{ strategies: ccts.outgoing, targetArray: outgoing },
{ strategies: ccts.incoming, targetArray: incoming },
{ strategies: ccts.foreign, targetArray: foreign }
]
try {

const ccts = await data.getStrategy(
targetChain,
fromSymbol,
targetSymbol,
);

const map = [
{ strategies: ccts.outgoing, targetArray: outgoing },
{ strategies: ccts.incoming, targetArray: incoming },
{ strategies: ccts.foreign, targetArray: foreign }
];

for (const { strategies, targetArray } of map) {
for (const strat of strategies) {
const strategyName: TStrategy = strategyMap[BigInt(strat).toString()] as TStrategy;
if (strategyName) {
targetArray.push(strategyName);
for (const { strategies, targetArray } of map) {
for (const strat of strategies) {
const strategyName: TStrategy = strategyMap[BigInt(strat).toString()] as TStrategy;
if (strategyName) {
targetArray.push(strategyName);
}
}
}

} catch (error) {

}

return {
outgoing,
incoming,
Expand Down Expand Up @@ -418,35 +425,42 @@ export async function web3Helper({
balance: async (addr) => (await fetchProvider()).getBalance(addr),
provider: async () => await fetchProvider(),
async estimateTime(targetChain, fromToken, targetToken) {
// Default time
let estimation: bigint = 2n * 60n * 1000n;

const ts = await data.getStrategy(
targetChain,
fromToken,
targetToken,
);

const outgoing = ts[0];
const foreign = ts[1];

const cctpBurn: bigint = BigInt(EStrategy.CCTPClaim);
const cctpClaim: bigint = BigInt(EStrategy.CCTPClaim);

const isCCTP =
foreign.includes(cctpBurn) ||
foreign.includes(cctpClaim) ||
outgoing.includes(cctpBurn) ||
outgoing.includes(cctpClaim);
try {

if (isCCTP) {
// 2 minutes
const timeInMs = (2n * 60n) * 1000n;
return timeInMs;
} else {
// 1 minute
const timeInMs = (1n * 60n) * 1000n;
return timeInMs;
const ts = await data.getStrategy(
targetChain,
fromToken,
targetToken,
);

const outgoing = ts[0];
const foreign = ts[1];

const cctpBurn: bigint = BigInt(EStrategy.CCTPClaim);
const cctpClaim: bigint = BigInt(EStrategy.CCTPClaim);

const isCCTP =
foreign.includes(cctpBurn) ||
foreign.includes(cctpClaim) ||
outgoing.includes(cctpBurn) ||
outgoing.includes(cctpClaim);

if (isCCTP) {
// 3 minutes
estimation = (3n * 60n) * 1000n;
} else {
// 1 minute
estimation = (1n * 60n) * 1000n;
}

} catch (error) {
console.warn(error)
}
return undefined;

return estimation;
},

async isTransferFromLp(targetChain, fromToken, targetToken) {
Expand Down
2 changes: 1 addition & 1 deletion src/factory/rpcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const MainnetRPCUri = {
"https://polygon-bor-rpc.publicnode.com",
"https://polygon-bor-rpc.publicnode.com",
"https://1rpc.io/matic",
"https://polygon.blockpi.network/v1/rpc/public",
// "https://polygon.blockpi.network/v1/rpc/public",
]

} as const;
Expand Down

0 comments on commit bb61743

Please sign in to comment.