Skip to content

Commit

Permalink
change to increase_allowance for cw funds + minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
simke9445 committed Mar 17, 2024
1 parent 9e4b9d7 commit ca26a18
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/composers/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class CreateJobMsgComposer {
private _executions: Execution[] = [];
private _durationDays: string;
private _fundingAccount: string;
private _cwFunds: warp_controller.CwFund[] = [];
private _operationalAmount: warp_controller.Uint128 | undefined;

static new(): CreateJobMsgComposer {
Expand Down Expand Up @@ -90,6 +91,11 @@ export class CreateJobMsgComposer {
return this;
}

cwFunds(cwFunds: warp_controller.CwFund[]): CreateJobMsgComposer {
this._cwFunds = cwFunds;
return this;
}

operationalAmount(operationalAmount: warp_controller.Uint128): CreateJobMsgComposer {
this._operationalAmount = operationalAmount;
return this;
Expand Down Expand Up @@ -136,6 +142,7 @@ export class CreateJobMsgComposer {
vars: JSON.stringify(this._vars),
assets_to_withdraw: this._assetsToWithdraw,
operational_amount: this._operationalAmount,
cw_funds: this._cwFunds,
funding_account: this._fundingAccount,
};

Expand Down
14 changes: 7 additions & 7 deletions src/modules/tx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { warp_controller, warp_account, warp_resolver, warp_templates } from '../types/contracts';
import { base64encode, nativeTokenDenom, Token, TransferMsg, TransferNftMsg } from '../utils';
import { ApproveNft, base64encode, IncreaseAllowanceMsg, nativeTokenDenom, Token, TransferMsg } from '../utils';
import { Coins, CreateTxOptions } from '@terra-money/feather.js';
import { TxBuilder } from '../tx';
import { JobSequenceMsgComposer } from '../composers';
Expand Down Expand Up @@ -260,19 +260,19 @@ export class TxModule {
if ('cw20' in fund) {
const { amount, contract_addr } = fund.cw20;

txBuilder = txBuilder.execute<TransferMsg>(sender, contract_addr, {
transfer: {
txBuilder = txBuilder.execute<IncreaseAllowanceMsg>(sender, contract_addr, {
increase_allowance: {
amount,
recipient: this.warpSdk.chain.contracts.controller,
spender: this.warpSdk.chain.contracts.controller,
},
});
} else if ('cw721' in fund) {
const { contract_addr, token_id } = fund.cw721;

txBuilder = txBuilder.execute<TransferNftMsg>(sender, contract_addr, {
transfer_nft: {
txBuilder = txBuilder.execute<ApproveNft>(sender, contract_addr, {
approve: {
token_id,
recipient: this.warpSdk.chain.contracts.controller,
spender: this.warpSdk.chain.contracts.controller,
},
});
}
Expand Down
14 changes: 14 additions & 0 deletions src/utils/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export const contractQuery = async <QueryMsg extends {}, QueryResponse>(
return await lcd.wasm.contractQuery<QueryResponse>(contractAddress, msg);
};

export type IncreaseAllowanceMsg = {
increase_allowance: {
spender: string;
amount: string;
};
};

export type TransferMsg = {
transfer: {
recipient: string;
Expand All @@ -22,6 +29,13 @@ export type TransferNftMsg = {
};
};

export type ApproveNft = {
approve: {
spender: string;
token_id: string;
};
};

export const base64encode = (input: any): string => {
return Buffer.from(JSON.stringify(JSON.parse(JSON.stringify(input)))).toString('base64');
};
Expand Down

0 comments on commit ca26a18

Please sign in to comment.