Skip to content
Draft
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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"typescript": "^5.7.3"
},
"dependencies": {
"@cowprotocol/app-data": "3.0.0-rc.1",
"@cowprotocol/sdk-app-data": "5.3.2",
"@cowprotocol/contracts": "^1.7.0",
"@cowprotocol/cow-sdk": "9.2.2",
"@cowprotocol/cow-sdk": "9.2.4",
"@cowprotocol/sdk-composable": "1.1.2",
"@cowprotocol/sdk-cow-shed": "0.4.1",
"@cowprotocol/sdk-ethers-v5-adapter": "0.4.10",
Expand Down
3 changes: 3 additions & 0 deletions src/const/gnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ export const GNO_ADDRESS = "0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb";
// See https://github.com/cowprotocol/composable-cow/pull/116
export const COMPOSABLE_COW_POLLER_ADDRESS =
"0xA360eE11eD0d2025604518CF4B8F6e6CB76C7Df7";

export const WXDAI_ADDRESS = "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d";
export const COW_ADDRESS = "0x177127622c4A00F3d409B75571e12cB3c8973d3c";
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import { run as swapSellWithSlippageTolerance } from "./scripts/sepolia/swapSell
import { run as approveTokenMainnet } from "./scripts/mainnet/approveTokenMainnet";
import { run as getQuoteAndPostOrderMainnet } from "./scripts/mainnet/getQuoteAndPostOrder";
import { run as approveTokenGnosis } from "./scripts/gnosis/approveTokenGnosis";
import { run as postHookOrderGnosis } from "./scripts/gnosis/postHookOrder";
import { run as probeWrappersAppData } from "./scripts/gnosis/probeWrappersAppData";
import { run as probeOrder1271Wrapper } from "./scripts/gnosis/probeOrder1271Wrapper";
import { run as swapAndBridgeSwapsIo } from "./scripts/bridging/swapAndBridgeSwapsIO";
import { run as approveTokenArbitrum } from "./scripts/arbitrum/approveTokenArbitrum";
import { run as swapAndBridgeAccrossArbitrum } from "./scripts/bridging/swapAndBridgeAccrossArbitrum";
Expand Down Expand Up @@ -88,7 +91,16 @@ const JOBS: (() => Promise<unknown>)[] = [
// minimalAppData,
// getIpfsForLegacyDoc,
// postTwapForEOA,
postTwapForEOAWithJitFunds,
// postTwapForEOAWithJitFunds,

// Post a Gnosis order carrying CoW hooks in appData (enforceable-hooks assumption test)
// postHookOrderGnosis,

// Probe: does the Gnosis orderbook accept an appData doc with a `wrappers` field?
// probeWrappersAppData,

// Probe: does the orderbook accept a 1271 order whose sig is only valid at settlement + wrappers?
probeOrder1271Wrapper,
];

async function main() {
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/app-data/getIpfsForLegacyDoc.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MetadataApi, stringifyDeterministic } from "@cowprotocol/app-data";
import { MetadataApi, stringifyDeterministic } from "@cowprotocol/sdk-app-data";

export async function run() {
const metadataApi = new MetadataApi();

const cid = await metadataApi.legacy.appDataHexToCidLegacy(
"0x46ff6f01739b9d0f95ce957468e01ef617abf89d29abfb673613e4f87ba86e29"
"0x46ff6f01739b9d0f95ce957468e01ef617abf89d29abfb673613e4f87ba86e29",
);
console.log("Cid: ", cid);
}
9 changes: 4 additions & 5 deletions src/scripts/app-data/minimalAppData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MetadataApi, stringifyDeterministic } from "@cowprotocol/app-data";
import { MetadataApi, stringifyDeterministic } from "@cowprotocol/sdk-app-data";

export async function run() {
const metadataApi = new MetadataApi();
Expand All @@ -11,14 +11,13 @@ export async function run() {
},
});

const { appDataContent, appDataHex, cid } = await metadataApi.getAppDataInfo(
appDataSchema
);
const { appDataContent, appDataHex, cid } =
await metadataApi.getAppDataInfo(appDataSchema);

console.log("App-data content (full app-data string): ", appDataContent);
console.log(
"App-data hex (app-data hex part of the order struct): ",
appDataHex
appDataHex,
);
console.log("App-data cid (IPFS identifier): ", cid);
}
18 changes: 9 additions & 9 deletions src/scripts/bridging/getAcrossBridgingId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { OrderBookApi } from "@cowprotocol/cow-sdk";

import { getRpcProvider, getWallet } from "../../utils";
import { Interface } from "ethers/lib/utils";
import { latest as latestAppData } from "@cowprotocol/app-data";
import { cowAppDataLatestScheme as latestAppData } from "@cowprotocol/sdk-app-data";

export const ACROSS_SPOOK_CONTRACT_ADDRESSES: Partial<
Record<TargetChainId, string>
Expand Down Expand Up @@ -47,7 +47,7 @@ async function getDepositId(
chainId: SupportedChainId,
orderId: string,
settlementTx: string,
rpc: providers.JsonRpcProvider
rpc: providers.JsonRpcProvider,
) {
const txReceipt = await rpc.getTransactionReceipt(settlementTx);

Expand All @@ -59,7 +59,7 @@ async function getDepositId(
if (depositEvents.length === 0) {
// This should never happen, means the hook was not triggered
throw new Error(
"No deposit events found in the settlement tx. Are you sure the hook was triggered?"
"No deposit events found in the settlement tx. Are you sure the hook was triggered?",
);
}

Expand All @@ -73,7 +73,7 @@ async function getDepositId(
console.log(
`Across Deposit - depositId: ${
deposit.depositId
}, Input: ${deposit.inputAmount.toString()}, Output: ${deposit.outputAmount.toString()}`
}, Input: ${deposit.inputAmount.toString()}, Output: ${deposit.outputAmount.toString()}`,
);
}

Expand All @@ -83,7 +83,7 @@ async function getDepositId(
// Fetch from API the details of all the settlement orders
const orderbookApi = new OrderBookApi({ chainId });
const ordersFromSettlement = await Promise.all(
cowTradeEvents.map((tradeEvent) => orderbookApi.getOrder(orderId))
cowTradeEvents.map((tradeEvent) => orderbookApi.getOrder(orderId)),
);

// Filter orders, leaving only cross-chain orders using Across provider
Expand All @@ -102,7 +102,7 @@ async function getDepositId(

// Find relative position for the orderId in the settlement tx
const orderIndex = crossChainOrdersAcross.findIndex(
(order) => order.uid === orderId
(order) => order.uid === orderId,
);

// Get the depositId from the relative position
Expand All @@ -113,7 +113,7 @@ async function getDepositId(

function getAcrossDepositEvents(
chainId: SupportedChainId,
logs: providers.Log[]
logs: providers.Log[],
): AcrossDepositEvent[] {
const spookContractAddress =
ACROSS_SPOOK_CONTRACT_ADDRESSES[chainId]?.toLowerCase();
Expand Down Expand Up @@ -168,7 +168,7 @@ function getAcrossDepositEvents(

function getCowTradeEvents(
chainId: SupportedChainId,
logs: providers.Log[]
logs: providers.Log[],
): CowTradeEvent[] {
const cowTradeEvents = logs.filter((log) => {
return log.address.toLocaleLowerCase() === COW_TRADE_EVENT_TOPIC;
Expand Down Expand Up @@ -242,7 +242,7 @@ export function getPostHooks(fullAppData?: string): latestAppData.CoWHook[] {

// TODO: Move to app-data project
export function isAppDoc(
appData: unknown
appData: unknown,
): appData is latestAppData.AppDataRootSchema {
return (
typeof appData === "object" &&
Expand Down
16 changes: 8 additions & 8 deletions src/scripts/bridging/swapAndBridgeAccrossArbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@cowprotocol/cow-sdk";
import { ethers } from "ethers";

import { MetadataApi } from "@cowprotocol/app-data";
import { MetadataApi } from "@cowprotocol/sdk-app-data";
import { confirm, getWallet, jsonReplacer } from "../../utils";
import { createCowShedTx } from "../../contracts/cowShed";
import {
Expand Down Expand Up @@ -81,7 +81,7 @@ export async function run() {

console.log(
"\n💰 Bridge tx:",
JSON.stringify(bridgeWithXdaiBridgeTx, jsonReplacer, 2)
JSON.stringify(bridgeWithXdaiBridgeTx, jsonReplacer, 2),
);

// Sign and encode the transaction
Expand Down Expand Up @@ -126,7 +126,7 @@ export async function run() {

console.log(
"🕣 Getting quote...",
JSON.stringify(parameters, jsonReplacer, 2)
JSON.stringify(parameters, jsonReplacer, 2),
);

quote = await sdk.getQuote(parameters, { appData });
Expand All @@ -136,19 +136,19 @@ export async function run() {
quoteResults.amountsAndCosts.afterSlippage.buyAmount;
const minIntermediateTokenAmountFormatted = ethers.utils.formatUnits(
minIntermediateTokenAmount,
intermediateTokenDecimals
intermediateTokenDecimals,
);
const sellAmountFormatted = ethers.utils.formatUnits(
sellAmount,
sellTokenDecimals
sellTokenDecimals,
);

console.log(
`You will sell ${sellAmountFormatted} USDC and receive at least ${minIntermediateTokenAmountFormatted} ${intermediateTokenSymbol} (intermediate token). Then, it will be bridged to Base for WETH.`
`You will sell ${sellAmountFormatted} USDC and receive at least ${minIntermediateTokenAmountFormatted} ${intermediateTokenSymbol} (intermediate token). Then, it will be bridged to Base for WETH.`,
);

const confirmed = await confirm(
`You will bridge at least ${minIntermediateTokenAmountFormatted} ${intermediateTokenSymbol}. ok?`
`You will bridge at least ${minIntermediateTokenAmountFormatted} ${intermediateTokenSymbol}. ok?`,
);
if (!confirmed) {
console.log("🚫 Aborted");
Expand All @@ -160,7 +160,7 @@ export async function run() {

// Print the order creation
console.log(
`ℹ️ Order created, id: https://explorer.cow.fi/orders/${orderId}?tab=overview`
`ℹ️ Order created, id: https://explorer.cow.fi/orders/${orderId}?tab=overview`,
);

// Wait for the bridge start
Expand Down
16 changes: 8 additions & 8 deletions src/scripts/bridging/swapAndBridgeAccrossMainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@cowprotocol/cow-sdk";
import { ethers } from "ethers";

import { MetadataApi } from "@cowprotocol/app-data";
import { MetadataApi } from "@cowprotocol/sdk-app-data";
import { confirm, getWallet, jsonReplacer } from "../../utils";
import { createCowShedTx } from "../../contracts/cowShed";
import {
Expand Down Expand Up @@ -84,7 +84,7 @@ export async function run() {

console.log(
"\n💰 Bridge tx:",
JSON.stringify(bridgeWithXdaiBridgeTx, jsonReplacer, 2)
JSON.stringify(bridgeWithXdaiBridgeTx, jsonReplacer, 2),
);

// Sign and encode the transaction
Expand Down Expand Up @@ -129,7 +129,7 @@ export async function run() {

console.log(
"🕣 Getting quote...",
JSON.stringify(parameters, jsonReplacer, 2)
JSON.stringify(parameters, jsonReplacer, 2),
);

quote = await sdk.getQuote(parameters, { appData });
Expand All @@ -139,19 +139,19 @@ export async function run() {
quoteResults.amountsAndCosts.afterSlippage.buyAmount;
const minIntermediateTokenAmountFormatted = ethers.utils.formatUnits(
minIntermediateTokenAmount,
intermediateTokenDecimals
intermediateTokenDecimals,
);
const sellAmountFormatted = ethers.utils.formatUnits(
sellAmount,
sellTokenDecimals
sellTokenDecimals,
);

console.log(
`You will sell ${sellAmountFormatted} USDC and receive at least ${minIntermediateTokenAmountFormatted} ${intermediateTokenSymbol} (intermediate token). Then, it will be bridged to Base for WETH.`
`You will sell ${sellAmountFormatted} USDC and receive at least ${minIntermediateTokenAmountFormatted} ${intermediateTokenSymbol} (intermediate token). Then, it will be bridged to Base for WETH.`,
);

const confirmed = await confirm(
`You will bridge at least ${minIntermediateTokenAmountFormatted} ${intermediateTokenSymbol}. ok?`
`You will bridge at least ${minIntermediateTokenAmountFormatted} ${intermediateTokenSymbol}. ok?`,
);
if (!confirmed) {
console.log("🚫 Aborted");
Expand All @@ -163,7 +163,7 @@ export async function run() {

// Print the order creation
console.log(
`ℹ️ Order created, id: https://explorer.cow.fi/orders/${orderId}?tab=overview`
`ℹ️ Order created, id: https://explorer.cow.fi/orders/${orderId}?tab=overview`,
);

// Wait for the bridge start
Expand Down
24 changes: 12 additions & 12 deletions src/scripts/bridging/swapAndBridgeSwapsIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TradeParameters,
TradingSdk,
} from "@cowprotocol/cow-sdk";
import { MetadataApi } from "@cowprotocol/app-data";
import { MetadataApi } from "@cowprotocol/sdk-app-data";

const { GNO_ADDRESS } = gnosis;
const { BTCB_ADDRESS } = bnbchain;
Expand Down Expand Up @@ -38,7 +38,7 @@ async function apiRequest(method: string, params: any, post: boolean = false) {
}

async function selectIntermediaryAddress(
quote: SwapsIoQuoteParams
quote: SwapsIoQuoteParams,
): Promise<Token> {
const selectData = await apiRequest("select", quote);
const decimals: Record<string, number> = {
Expand Down Expand Up @@ -142,15 +142,15 @@ export async function run() {
console.log(
`Estimated intermediary token received: ${ethers.utils.formatUnits(
minBuyAmount,
intermediaryToken.decimals
)}`
intermediaryToken.decimals,
)}`,
);

// ----------------------------
// STEP C: Get cross-chain quote for final token on destination chain
// ----------------------------
console.log(
"Fetching cross-chain quote on Swaps.io for final token on destination chain..."
"Fetching cross-chain quote on Swaps.io for final token on destination chain...",
);
const crossChainQuoteParams = {
...selectQuoteParams,
Expand All @@ -160,7 +160,7 @@ export async function run() {
const crossChainQuote = await getCrossChainQuote(crossChainQuoteParams);
const formattedFinalAmount = ethers.utils.formatUnits(
crossChainQuote.data.order.toAmount.toString(),
dstToken.decimals
dstToken.decimals,
);
console.log(`You will receive ${formattedFinalAmount} BTCB on BNB chain.`);

Expand All @@ -187,7 +187,7 @@ export async function run() {
const signature = await wallet._signTypedData(
domain,
{ ExecuteHooks: types["ExecuteHooks"], Call: types["Call"] },
message
message,
);

// ----------------------------
Expand Down Expand Up @@ -232,7 +232,7 @@ export async function run() {

console.log(
"🕣 Getting quote...",
JSON.stringify(parameters, jsonReplacer, 2)
JSON.stringify(parameters, jsonReplacer, 2),
);

// TODO: This is the second quote we ask to the API. I understand why, its because first one is to estimate how many intermediate tokens we get, and the second one is to re-estimate once we have the hook. In principle, we should need one if we can use already a gas estimation and a mock hook at the begining.
Expand All @@ -242,11 +242,11 @@ export async function run() {
const maxSellAmount = quoteResults.amountsAndCosts.afterSlippage.sellAmount;
const maxSellAmountFormatted = ethers.utils.formatUnits(
maxSellAmount,
srcToken.decimals
srcToken.decimals,
);

const confirmed = await confirm(
`You will sell at most ${maxSellAmountFormatted} GNO to buy ${formattedFinalAmount} BTCB on BNB chain. ok?`
`You will sell at most ${maxSellAmountFormatted} GNO to buy ${formattedFinalAmount} BTCB on BNB chain. ok?`,
);
if (!confirmed) {
console.log("🚫 Aborted");
Expand All @@ -260,13 +260,13 @@ export async function run() {

// Print the order creation
console.log(
`ℹ️ Order created, id: https://explorer.cow.fi/orders/${orderId}?tab=overview`
`ℹ️ Order created, id: https://explorer.cow.fi/orders/${orderId}?tab=overview`,
);

// Wait for the cross-chain swap start
console.log("🕣 Waiting for the cross-chain swap to start...");
console.log(
`🔗 Swaps.io Explorer link: https://api.prod.swaps.io/api/v0/swaps/${swapHash}`
`🔗 Swaps.io Explorer link: https://api.prod.swaps.io/api/v0/swaps/${swapHash}`,
);
// TODO: Implement

Expand Down
Loading