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

feat: add params to save swap history #228

Merged
merged 1 commit into from
Sep 7, 2023
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
6 changes: 5 additions & 1 deletion apps/docs/pages/core/modules/exchange.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ walletApiClient.exchange.complete(params: {
hexSignature: string,
feeStrategy: 'SLOW' | 'MEDIUM' | 'FAST',
exchangeType: 'SWAP' | 'SELL' | 'FUND',
toAccountId?: string
toAccountId?: string,
swapId?: string,
rate?: number,
}): Promise<{ transactionHash: string }>
```

Expand All @@ -60,6 +62,8 @@ walletApiClient.exchange.complete(params: {
- `feeStrategy` (required): A string representing the fee strategy (`"SLOW"`, `"MEDIUM"`, or `"FAST"`).
- `exchangeType` (required): A string specifying the type of exchange operation (`"SWAP"`, `"SELL"`, or `"FUND"`).
- `toAccountId` (optional): Identifier of the account used as a destination (required for `"SWAP"`).
- `swapId` (optional): Identifier of the backend swap used (required for `"SWAP"`).
- `rate` (optional): Swap rate used in the transaction (required for `"SWAP"`).

**Returns**: A promise that resolves with an object containing the `transactionHash` of the broadcasted transaction.

Expand Down
2 changes: 2 additions & 0 deletions apps/wallet-api-tools/src/TemplateSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ const data: Group[] = [
hexBinaryPayload: "",
hexSignature: "",
feeStrategy: "SLOW | MEDIUM | FAST | CUSTOM",
swapId: "1234",
rate: 1,
},
},
},
Expand Down
8 changes: 8 additions & 0 deletions packages/client/src/modules/Exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export class ExchangeModule {
* @param provider - Used to verify the signature
* @param fromAccountId - Identifier of the account used as a source for the tx
* @param toAccountId - Identifier of the account used as a destination
* @param swapId - Identifier of the swap used by backend
* @param rate - Swap rate in the transaction
* @param transaction - Transaction containing the recipient and amount
* @param binaryPayload - Blueprint of the data that we'll allow signing
* @param signature - Ensures the source of the payload
Expand All @@ -54,6 +56,8 @@ export class ExchangeModule {
provider,
fromAccountId,
toAccountId,
swapId,
rate,
transaction,
binaryPayload,
signature,
Expand All @@ -62,6 +66,8 @@ export class ExchangeModule {
provider: string;
fromAccountId: string;
toAccountId: string;
swapId: string;
rate: number;
transaction: Transaction;
binaryPayload: Buffer;
signature: Buffer;
Expand All @@ -74,6 +80,8 @@ export class ExchangeModule {
provider,
fromAccountId,
toAccountId,
swapId,
rate,
rawTransaction: serializeTransaction(transaction),
hexBinaryPayload: binaryPayload.toString("hex"),
hexSignature: signature.toString("hex"),
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/spec/types/ExchangeComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const schemaExchangeCompleteSwapParams =
schemaExchangeCompleteBaseParams.extend({
exchangeType: z.literal("SWAP"),
toAccountId: z.string(),
swapId: z.string(),
rate: z.number(),
});

const schemaExchangeCompleteParams = z.discriminatedUnion("exchangeType", [
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/internalHandlers/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export const complete: RPCHandler<ExchangeComplete["result"]> = async (
...commonParams,
exchangeType: safeParams.exchangeType,
toAccount,
swapId: safeParams.swapId,
rate: safeParams.rate,
});

return { transactionHash };
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type ExchangeSellParams = {
type ExchangeSwapParams = {
exchangeType: "SWAP";
toAccount: Account;
swapId: string;
rate: number;
} & ExchangeBaseParams;

type ExchangeParams =
Expand Down
6 changes: 5 additions & 1 deletion spec/rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ Returns the broadcasted transaction details.
- `signature (hexString)`: Ensures the source of the payload
- `feesStrategy (FeesLevel)`: Slow / Medium / Fast
- `exchangeType (ExchangeType)`: used by the exchange transport to discern between swap/sell/fund
- `swapId (string)`: (Swap) Live identifier of the swap used by backend
- `rate (number)`: (Swap) Rate provider used in the transaction

#### Request

Expand All @@ -376,7 +378,9 @@ Returns the broadcasted transaction details.
"binaryPayload": "",
"signature": "",
"feesStrategy": "medium",
"exchangeType": "SWAP"
"exchangeType": "SWAP",
"swapId": "1234",
"rate": 1,
}
}
```
Expand Down