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

portico: pass portico bridge instance instead of destination address #740

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions connect/src/routes/portico/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,15 @@ export class AutomaticPorticoRoute<N extends Network>
const destToken = request.destination!.id;

const fromPorticoBridge = await request.fromChain.getPorticoBridge();
const tokenGroup = fromPorticoBridge.getTokenGroup(sourceToken.toString());
const toPorticoBridge = await request.toChain.getPorticoBridge();
const destPorticoAddress = toPorticoBridge.getPorticoAddress(tokenGroup);

const xfer = fromPorticoBridge.transfer(
Wormhole.parseAddress(sender.chain(), sender.address()),
to,
sourceToken,
amount.units(params.normalizedParams.amount),
destToken!,
destPorticoAddress,
toPorticoBridge,
details!,
);

Expand Down
4 changes: 3 additions & 1 deletion core/definitions/src/protocols/portico/portico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export interface PorticoBridge<N extends Network = Network, C extends Chain = Ch
token: TokenAddress<C>,
amount: bigint,
destToken: TokenId,
destPorticoAddress: string,
toPorticoBridge: PorticoBridge<N>,
quote: PorticoBridge.Quote,
): AsyncGenerator<UnsignedTransaction<N, C>>;

Expand Down Expand Up @@ -113,4 +113,6 @@ export interface PorticoBridge<N extends Network = Network, C extends Chain = Ch

/** Get the Portico contract address for the token group */
getPorticoAddress(group: string): string;

getChain(): Chain;
}
19 changes: 18 additions & 1 deletion platforms/evm/protocols/portico/src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,22 @@ export class EvmPorticoBridge<
token: TokenAddress<C>,
amount: bigint,
destToken: TokenId,
destinationPorticoAddress: string,
toPorticoBridge: PorticoBridge<N>,
quote: PorticoBridge.Quote,
) {
const toChain = toPorticoBridge.getChain();
if (this.chain === toChain) {
throw new Error('Cannot transfer to the same chain');
}

if (receiver.chain !== toChain) {
throw new Error('Invalid destination chain');
}

const tokenGroup = this.getTokenGroup(token.toString());
const destinationPorticoAddress =
toPorticoBridge.getPorticoAddress(tokenGroup);

const { minAmountStart, minAmountFinish } = quote.swapAmounts;
if (minAmountStart === 0n) throw new Error('Invalid min swap amount');
if (minAmountFinish === 0n) throw new Error('Invalid min swap amount');
Expand Down Expand Up @@ -296,6 +309,10 @@ export class EvmPorticoBridge<
return token.group;
}

getChain() {
return this.chain;
}

private async *approve(
token: string,
senderAddr: string,
Expand Down
Loading