From ca26a183907f3d5e7ba48eea681b390a2d3b1a86 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Sun, 17 Mar 2024 22:25:42 +0100 Subject: [PATCH] change to increase_allowance for cw funds + minor improvements --- src/composers/job.ts | 7 +++++++ src/modules/tx.ts | 14 +++++++------- src/utils/contract.ts | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/composers/job.ts b/src/composers/job.ts index 620ecb8..7b42ffd 100644 --- a/src/composers/job.ts +++ b/src/composers/job.ts @@ -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 { @@ -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; @@ -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, }; diff --git a/src/modules/tx.ts b/src/modules/tx.ts index 7241094..881ca7a 100644 --- a/src/modules/tx.ts +++ b/src/modules/tx.ts @@ -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'; @@ -260,19 +260,19 @@ export class TxModule { if ('cw20' in fund) { const { amount, contract_addr } = fund.cw20; - txBuilder = txBuilder.execute(sender, contract_addr, { - transfer: { + txBuilder = txBuilder.execute(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(sender, contract_addr, { - transfer_nft: { + txBuilder = txBuilder.execute(sender, contract_addr, { + approve: { token_id, - recipient: this.warpSdk.chain.contracts.controller, + spender: this.warpSdk.chain.contracts.controller, }, }); } diff --git a/src/utils/contract.ts b/src/utils/contract.ts index a1a5563..bc88303 100644 --- a/src/utils/contract.ts +++ b/src/utils/contract.ts @@ -8,6 +8,13 @@ export const contractQuery = async ( return await lcd.wasm.contractQuery(contractAddress, msg); }; +export type IncreaseAllowanceMsg = { + increase_allowance: { + spender: string; + amount: string; + }; +}; + export type TransferMsg = { transfer: { recipient: string; @@ -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'); };