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

support propose safe tx to apollo #52

Merged
merged 2 commits into from
Feb 26, 2025
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
76 changes: 76 additions & 0 deletions src/base/safe-service/apollo.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { SafeMultisigConfirmationResponse } from "@safe-global/safe-core-sdk-types";
import { ProposeTransactionProps } from "@safe-global/api-kit";
import { SafeService } from "./safe.service";
import { ethers } from "ethers";
import axios from "axios";

export class ApolloService extends SafeService {
private chainId: number;
private privateKey: string;

constructor(chainId: number, apolloUrl: string) {
super("apollo", apolloUrl);
this.chainId = chainId;
}

async proposeTransaction({
safeAddress,
safeTransactionData,
safeTxHash,
senderAddress,
senderSignature,
origin,
}: ProposeTransactionProps): Promise<void> {
const mutation = `mutation {
proposeSafeTransaction(
owner: "${senderAddress}",
safeAddress: "${safeAddress}",
chainId: ${this.chainId},
signature: "${senderSignature}",
signatureType: "ECDSA",
transactionHash: "${safeTxHash}",
nonce: ${safeTransactionData.nonce},
confirmationType: "approve"
)}`;
await axios.post(this.url, {
query: mutation,
variables: null,
});
}

async getTransactionConfirmations(
safeTxHash: string
): Promise<SafeMultisigConfirmationResponse[]> {
const query = `{
getTransactionConfirmations(
safeTxHash: \"${safeTxHash}\"
) {
owner, signature, signatureType, transactionHash, confirmationType
}
}`;
const confirmations = await axios
.post(this.url, {
query,
variables: {},
operationName: null,
})
.then((res) => res.data.data.getTransactionConfirmations);

const validConfirmations = confirmations.filter((confirmation) => {
const { signature } = confirmation;
let signatureV: number = parseInt(signature.slice(-2), 16);
if (signatureV !== 31 && signatureV !== 32) {
return false;
}
signatureV -= 4;
const normalizedSignature =
signature.slice(0, -2) + signatureV.toString(16);
return (
ethers
.verifyMessage(ethers.getBytes(safeTxHash), normalizedSignature)
.toLowerCase() === confirmation.owner.toLowerCase()
);
});
return validConfirmations;
}
}
1 change: 0 additions & 1 deletion src/base/safe-service/safeglobal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class SafeGlobalService extends SafeService {
await this.safeService.proposeTransaction(props);
}


async getTransactionConfirmations(
safeTxHash: string
): Promise<SafeMultisigConfirmationResponse[]> {
Expand Down
17 changes: 10 additions & 7 deletions src/base/safewallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
SafeTransaction,
SafeMultisigConfirmationResponse,
} from "@safe-global/safe-core-sdk-types";
import Safe, { buildSignatureBytes, EthSafeSignature } from "@safe-global/protocol-kit";
import Safe, {
buildSignatureBytes,
EthSafeSignature,
} from "@safe-global/protocol-kit";
import { ethers, Wallet, HDNodeWallet } from "ethers";
import { SafeService } from "./safe-service/safe.service";
import { EthereumConnectedWallet } from "./wallet";
Expand Down Expand Up @@ -109,7 +112,7 @@ export class SafeWallet {
return {
readyExecute: true,
safeTransaction: tx,
signatures: signedTransaction.encodedSignatures()
signatures: signedTransaction.encodedSignatures(),
};
} else {
return null;
Expand All @@ -118,7 +121,7 @@ export class SafeWallet {
let confirmations: SafeMultisigConfirmationResponse[];
try {
confirmations = await this.safeService.getTransactionConfirmations(
txHash
txHash
);
} catch {
confirmations = [];
Expand All @@ -135,7 +138,7 @@ export class SafeWallet {
} else {
if (signatureInfo.size < this.threshold) {
try {
const senderSignature = await this.safeSdk.signHash(txHash)
const senderSignature = await this.safeSdk.signHash(txHash);
await this.safeService.proposeTransaction({
safeAddress: this.address,
safeTransactionData: tx.data,
Expand All @@ -159,14 +162,14 @@ export class SafeWallet {
return {
readyExecute: false,
safeTransaction: tx,
signatures: signatureInfo.signatures
}
signatures: signatureInfo.signatures,
};
}
// isExecuter
return {
readyExecute: readyExecute,
safeTransaction: tx,
signatures: signatureInfo.signatures
signatures: signatureInfo.signatures,
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/configure/configure.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface BridgeInfo {
safeWalletAddress: string | undefined;
safeWalletUrl: string | undefined;
safeWalletRole: string | undefined;
safeWalletType: "gnosis" | "ceramic" | "single" | undefined;
safeWalletType: "gnosis" | "ceramic" | "single" | "apollo" | undefined;
minProfit: number;
maxProfit: number;
tokens: TokenInfo[];
Expand Down
7 changes: 1 addition & 6 deletions src/liquidity/lend/aave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ import {
WETHContract,
Erc20Contract,
} from "../../base/contract";
import {
LendMarket,
TxInfo,
WithdrawBorrowBalance,
maxU256,
} from "./market";
import { LendMarket, TxInfo, WithdrawBorrowBalance, maxU256 } from "./market";
import {
LendTokenInfo,
CollateralInfo,
Expand Down
7 changes: 1 addition & 6 deletions src/liquidity/lend/moonwell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ import {
Erc20Contract,
MulticallArgs,
} from "../../base/contract";
import {
LendMarket,
TxInfo,
WithdrawBorrowBalance,
maxU256,
} from "./market";
import { LendMarket, TxInfo, WithdrawBorrowBalance, maxU256 } from "./market";
import { Any } from "../../base/bignumber";
import { EthereumConnectedWallet } from "../../base/wallet";
import { EthereumProvider } from "../../base/provider";
Expand Down
15 changes: 12 additions & 3 deletions src/relayer/relayer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { LendMarket } from "../liquidity/lend/market";
import { CeramicService } from "../base/safe-service/ceramic.service";
import { SingleService } from "../base/safe-service/single.service";
import { SafeGlobalService } from "../base/safe-service/safeglobal.service";
import { ApolloService } from "../base/safe-service/apollo.service";
import { SafeService } from "../base/safe-service/safe.service";
import { gasPriceToString } from "../base/provider";

Expand Down Expand Up @@ -165,7 +166,9 @@ export class RelayerService implements OnModuleInit {
timer.lastRepayLend = 0;
}
} catch (err) {
this.logger.warn(`[${key}]try to check repay dept failed, err: ${err}`);
this.logger.warn(
`[${key}]try to check repay dept failed, err: ${err}`
);
}
}
timer.isProcessing = false;
Expand Down Expand Up @@ -295,6 +298,11 @@ export class RelayerService implements OnModuleInit {
? new CeramicService(ceramicKey, config.safeWalletUrl)
: config.safeWalletType === "single"
? new SingleService()
: config.safeWalletType === "apollo"
? new ApolloService(
toChainInfo.chainId,
this.configureService.indexer
)
: new SafeGlobalService(
config.safeWalletUrl,
toChainInfo.chainId
Expand Down Expand Up @@ -920,11 +928,12 @@ export class RelayerService implements OnModuleInit {
}
let amountThreshold = kMaxWithdrawTransferAmount;
if (lnProvider.withdrawLiquidityAmountThreshold) {
amountThreshold = lnProvider.withdrawLiquidityAmountThreshold
amountThreshold = lnProvider.withdrawLiquidityAmountThreshold;
}
if (
filterTransferIds.length >= countThreshold ||
Number(totalAmount) / Number(new Any(1, srcDecimals).Number) >= amountThreshold
Number(totalAmount) / Number(new Any(1, srcDecimals).Number) >=
amountThreshold
) {
// token transfer direction fromChain -> toChain
// withdrawLiquidity message direction toChain -> fromChain
Expand Down