-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* allow pre-encoded message * test with simple transfer * add changeset * assert message
- Loading branch information
1 parent
bb73f49
commit 6c46231
Showing
4 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@across-protocol/app-sdk": patch | ||
--- | ||
|
||
Allow passing of pre encoded message field in getQuote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { assert, assertType, describe, test } from "vitest"; | ||
import { testClient } from "../../common/sdk.js"; | ||
import { | ||
buildMulticallHandlerMessage, | ||
getMultiCallHandlerAddress, | ||
type Quote, | ||
type Route, | ||
} from "../../../src/index.js"; | ||
import { encodeFunctionData, erc20Abi, parseUnits } from "viem"; | ||
import { arbitrum, optimism } from "viem/chains"; | ||
|
||
// arbitrum USDC | ||
const inputToken = { | ||
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", | ||
symbol: "USDC", | ||
name: "USD Coin", | ||
decimals: 6, | ||
} as const; | ||
|
||
// optimism USDC | ||
const outputToken = { | ||
address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85", | ||
symbol: "USDC", | ||
name: "USD Coin", | ||
decimals: 6, | ||
} as const; | ||
|
||
const testEoa = "0x9A8f92a830A5cB89a3816e3D267CB7791c16b04D"; | ||
const inputAmount = 100; | ||
const inputAmountBN = parseUnits(inputAmount.toString(), inputToken.decimals); | ||
const outputAmountBN = inputAmountBN / 2n; // 50% of input ensures this doesn't fail, since we cannot recompute after getting the initial quote | ||
|
||
// ARBITRUM => OPTIMISM | ||
const testRoute: Route = { | ||
originChainId: arbitrum.id, | ||
destinationChainId: optimism.id, | ||
inputToken: inputToken.address, | ||
outputToken: outputToken.address, | ||
inputTokenSymbol: inputToken.symbol, | ||
outputTokenSymbol: outputToken.symbol, | ||
isNative: false, | ||
}; | ||
|
||
describe("getQuote with Raw Pre-Encoded Message", () => { | ||
test("Gets a quote using a raw pre-encoded message from a test EOA", async () => { | ||
// pre compute a simple transfer message | ||
const calldata = buildMulticallHandlerMessage({ | ||
fallbackRecipient: testEoa, | ||
actions: [ | ||
{ | ||
target: outputToken.address, | ||
value: 0n, | ||
callData: encodeFunctionData({ | ||
abi: erc20Abi, | ||
functionName: "transfer", | ||
args: [testEoa, outputAmountBN], | ||
}), | ||
}, | ||
], | ||
}); | ||
|
||
// Invoke getQuote with the raw message | ||
const _quote = await testClient.getQuote({ | ||
route: testRoute, | ||
recipient: getMultiCallHandlerAddress(testRoute.destinationChainId), | ||
inputAmount: inputAmountBN, | ||
crossChainMessage: calldata, | ||
// Removed 'sender' as it's not a parameter for getQuote | ||
}); | ||
|
||
// Assert that a quote was returned | ||
assert(_quote, "No quote returned for the provided route and message"); | ||
assertType<Quote>(_quote); | ||
|
||
assert.equal( | ||
_quote.deposit.message, | ||
calldata, | ||
"Message should be equal to pre-encoded calldata", | ||
); | ||
|
||
// Optional: Additional assertions to verify quote details | ||
assert.equal( | ||
_quote.deposit.inputAmount.toString(), | ||
inputAmountBN.toString(), | ||
"Input amounts should match", | ||
); | ||
assert.equal( | ||
_quote.deposit.originChainId, | ||
testRoute.originChainId, | ||
"Origin chain IDs should match", | ||
); | ||
assert.equal( | ||
_quote.deposit.destinationChainId, | ||
testRoute.destinationChainId, | ||
"Destination chain IDs should match", | ||
); | ||
assert.equal( | ||
_quote.deposit.inputToken, | ||
testRoute.inputToken, | ||
"Input tokens should match", | ||
); | ||
assert.equal( | ||
_quote.deposit.outputToken, | ||
testRoute.outputToken, | ||
"Output tokens should match", | ||
); | ||
}); | ||
}); |