Skip to content

Commit

Permalink
fix: on/offramp reference
Browse files Browse the repository at this point in the history
  • Loading branch information
okjodom committed Nov 12, 2024
1 parent 7bab370 commit 2e14756
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 26 deletions.
8 changes: 4 additions & 4 deletions apps/api/src/swap/swap.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('SwapController', () => {
it('should call swapService.postOnrampTransaction', () => {
const req = {
quote: undefined,
ref: 'ref',
reference: 'ref',
amountFiat: '100',
source: {
currency: Currency.KES,
Expand All @@ -80,7 +80,7 @@ describe('SwapController', () => {
},
},
target: {
invoice: {
payout: {
invoice: 'lnbc1000u1p0j7j0pp5',
},
},
Expand Down Expand Up @@ -115,11 +115,11 @@ describe('SwapController', () => {
it('should call swapService.postOfframpTransaction', () => {
const req = {
quote: undefined,
ref: 'ref',
reference: 'ref',
amountFiat: '100',
target: {
currency: SupportedCurrencies.KES,
destination: {
payout: {
phone: '07000000000',
},
},
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/swap/swap.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ export class SwapController {
@ApiOperation({ summary: 'List onramp swaps' })
@ApiQuery({
name: 'page',
example: '?page=0',
example: '0',
type: ListSwapsDto['page'],
required: false,
})
@ApiQuery({
name: 'size',
example: '?size=100',
example: '100',
type: ListSwapsDto['size'],
required: false,
})
Expand Down Expand Up @@ -139,13 +139,13 @@ export class SwapController {
@ApiOperation({ summary: 'List offramp swaps' })
@ApiQuery({
name: 'page',
example: '?page=0',
example: '0',
type: ListSwapsDto['page'],
required: false,
})
@ApiQuery({
name: 'size',
example: '?size=100',
example: '100',
type: ListSwapsDto['size'],
required: false,
})
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/swap/swap.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('SwapService', () => {
it('can initiate an onramp swap without a quote', () => {
const swap = swapService.postOnrampTransaction({
quote: undefined,
ref: '1234',
reference: 'ref',
amountFiat: '100',
source: {
currency: Currency.KES,
Expand All @@ -167,7 +167,7 @@ describe('SwapService', () => {

it('can initiate an onramp swap with a quote', () => {
const swap = swapService.postOnrampTransaction({
ref: '1234',
reference: 'ref',
amountFiat: '100',
source: {
currency: Currency.KES,
Expand Down Expand Up @@ -229,7 +229,7 @@ describe('SwapService', () => {
it('can initiate an offramp swap without a quote', () => {
const swap = swapService.postOfframpTransaction({
quote: undefined,
ref: '1234',
reference: 'ref',
amountFiat: '100',
target: {
currency: Currency.KES,
Expand All @@ -244,7 +244,7 @@ describe('SwapService', () => {

it('can initiate an offramp swap with a quote', () => {
const swap = swapService.postOfframpTransaction({
ref: '1234',
reference: 'ref',
amountFiat: '100',
target: {
currency: Currency.KES,
Expand Down
20 changes: 12 additions & 8 deletions apps/swap/src/swap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class SwapService {
amountFiat,
source,
target,
ref,
reference,
}: CreateOnrampSwapDto): Promise<SwapResponse> {
const rate = await this.getRate(quote, {
from: Currency.KES,
Expand All @@ -152,7 +152,7 @@ export class SwapService {
});

const swap = await this.onramp.create({
reference: ref,
reference,
state: SwapTransactionState.PENDING,
lightning: target.payout.invoice,
amountSats: amountSats.toFixed(2),
Expand All @@ -163,7 +163,7 @@ export class SwapService {
const mpesa = await this.intasendService.sendMpesaStkPush({
amount: Number(amountFiat),
phone_number: source.origin.phone,
api_ref: ref,
api_ref: reference,
});

const updatedSwap = await this.onramp.findOneAndUpdate(
Expand Down Expand Up @@ -230,10 +230,10 @@ export class SwapService {
}

async createOfframpSwap({
ref,
quote,
amountFiat,
target,
reference,
}: CreateOfframpSwapDto): Promise<SwapResponse> {
const rate = await this.getRate(quote, {
from: Currency.BTC,
Expand All @@ -246,13 +246,13 @@ export class SwapService {
});

const { invoice: lightning, operationId: id } =
await this.fedimintService.invoice(amountMsats, ref || 'offramp');
await this.fedimintService.invoice(amountMsats, reference);

const swap = await this.offramp.create({
rate,
reference,
lightning,
retryCount: 0,
reference: 'ref',
phone: target.payout.phone,
amountSats: amountSats.toFixed(2),
state: SwapTransactionState.PENDING,
Expand Down Expand Up @@ -442,15 +442,19 @@ export class SwapService {
},
);

this.logger.log(`Received lightning payment for ${context} : ${operationId}`);
this.logger.log(
`Received lightning payment for ${context} : ${operationId}`,
);
}

@OnEvent(fedimint_receive_failure)
private async handleFailedReceive({
context,
operationId,
}: ReceivePaymentFailureEvent) {
this.logger.log(`Failed to eceive lightning payment for ${context} : ${operationId}`);
this.logger.log(
`Failed to eceive lightning payment for ${context} : ${operationId}`,
);

await this.offramp.findOneAndUpdate(
{ _id: operationId },
Expand Down
2 changes: 1 addition & 1 deletion libs/common/src/dto/create-offramp-swap.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class CreateOfframpSwapDto implements OfframpSwapRequest {
@IsString()
@Type(() => String)
@ApiProperty()
ref: string;
reference: string;

@IsNotEmpty()
@IsString()
Expand Down
2 changes: 1 addition & 1 deletion libs/common/src/dto/create-onramp-swap.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class CreateOnrampSwapDto implements OnrampSwapRequest {
@IsString()
@Type(() => String)
@ApiProperty()
ref: string;
reference: string;

@IsNotEmpty()
@IsString()
Expand Down
4 changes: 3 additions & 1 deletion libs/common/src/types/proto/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export interface OnrampSwapRequest {
*/
quote?: Quote | undefined;
/** Swap initiator reference to the account this transaction is associated with. */
ref: string;
reference: string;
/**
* Amount to swap
* Any transaction fees will be deducted from this amount
Expand Down Expand Up @@ -118,6 +118,8 @@ export interface OfframpSwapRequest {
* If not specified, the service will create a new quote for the swap
*/
quote?: Quote | undefined;
/** Swap initiator reference to the account this transaction is associated with. */
reference: string;
/**
* Amount to swap
* Any transaction fees will be deducted from this amount
Expand Down
9 changes: 6 additions & 3 deletions proto/swap.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ message OnrampSwapRequest {
optional Quote quote = 1;

// Swap initiator reference to the account this transaction is associated with.
string ref = 2;
string reference = 2;

// Amount to swap
// Any transaction fees will be deducted from this amount
Expand Down Expand Up @@ -117,12 +117,15 @@ message OfframpSwapRequest {
// If not specified, the service will create a new quote for the swap
optional Quote quote = 1;

// Swap initiator reference to the account this transaction is associated with.
string reference = 2;

// Amount to swap
// Any transaction fees will be deducted from this amount
string amountFiat = 2;
string amountFiat = 3;

// Target of the swap
OfframpSwapTarget target = 3;
OfframpSwapTarget target = 4;
}

message OfframpSwapTarget {
Expand Down

0 comments on commit 2e14756

Please sign in to comment.