@heyanon/sdk 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Address, PublicClient } from 'viem';
|
|
2
|
+
import { TransactionParams } from '../../blockchain';
|
|
3
|
+
interface Props {
|
|
4
|
+
readonly args: {
|
|
5
|
+
readonly account: Address;
|
|
6
|
+
readonly target: Address;
|
|
7
|
+
readonly spender: Address;
|
|
8
|
+
readonly amount: bigint;
|
|
9
|
+
};
|
|
10
|
+
readonly provider: PublicClient;
|
|
11
|
+
readonly transactions: TransactionParams[];
|
|
12
|
+
}
|
|
13
|
+
export declare function checkToApprove({ args, transactions, provider }: Props): Promise<void>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var sdk = require('@real-wagmi/sdk');
|
|
4
|
+
var viem = require('viem');
|
|
4
5
|
|
|
5
6
|
// src/adapter/transformers/toResult.ts
|
|
6
7
|
function toResult(data = "", error = false) {
|
|
@@ -104,6 +105,25 @@ function getWrappedNative(chainId) {
|
|
|
104
105
|
}
|
|
105
106
|
return token;
|
|
106
107
|
}
|
|
108
|
+
async function checkToApprove({ args, transactions, provider }) {
|
|
109
|
+
const { account, target, spender, amount } = args;
|
|
110
|
+
const allowance = await provider.readContract({
|
|
111
|
+
address: target,
|
|
112
|
+
abi: viem.erc20Abi,
|
|
113
|
+
functionName: "allowance",
|
|
114
|
+
args: [account, spender]
|
|
115
|
+
});
|
|
116
|
+
if (allowance < amount) {
|
|
117
|
+
transactions.push({
|
|
118
|
+
target,
|
|
119
|
+
data: viem.encodeFunctionData({
|
|
120
|
+
abi: viem.erc20Abi,
|
|
121
|
+
functionName: "approve",
|
|
122
|
+
args: [spender, amount]
|
|
123
|
+
})
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
107
127
|
|
|
108
128
|
// src/utils/retry.ts
|
|
109
129
|
function delay(ms) {
|
|
@@ -135,6 +155,7 @@ exports.WETH9 = WETH9;
|
|
|
135
155
|
exports.allChainIds = allChainIds;
|
|
136
156
|
exports.allChainNames = allChainNames;
|
|
137
157
|
exports.chainNames = chainNames;
|
|
158
|
+
exports.checkToApprove = checkToApprove;
|
|
138
159
|
exports.getChainFromName = getChainFromName;
|
|
139
160
|
exports.getChainName = getChainName;
|
|
140
161
|
exports.getWrappedNative = getWrappedNative;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ethereumTokens, optimismTokens, bscTokens, polygonTokens, fantomTokens, zkSyncTokens, kavaTokens, avalancheTokens, arbitrumTokens, metisTokens, baseTokens, iotaTokens, sonicTokens, Token } from '@real-wagmi/sdk';
|
|
2
|
+
import { erc20Abi, encodeFunctionData } from 'viem';
|
|
2
3
|
|
|
3
4
|
// src/adapter/transformers/toResult.ts
|
|
4
5
|
function toResult(data = "", error = false) {
|
|
@@ -102,6 +103,25 @@ function getWrappedNative(chainId) {
|
|
|
102
103
|
}
|
|
103
104
|
return token;
|
|
104
105
|
}
|
|
106
|
+
async function checkToApprove({ args, transactions, provider }) {
|
|
107
|
+
const { account, target, spender, amount } = args;
|
|
108
|
+
const allowance = await provider.readContract({
|
|
109
|
+
address: target,
|
|
110
|
+
abi: erc20Abi,
|
|
111
|
+
functionName: "allowance",
|
|
112
|
+
args: [account, spender]
|
|
113
|
+
});
|
|
114
|
+
if (allowance < amount) {
|
|
115
|
+
transactions.push({
|
|
116
|
+
target,
|
|
117
|
+
data: encodeFunctionData({
|
|
118
|
+
abi: erc20Abi,
|
|
119
|
+
functionName: "approve",
|
|
120
|
+
args: [spender, amount]
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
105
125
|
|
|
106
126
|
// src/utils/retry.ts
|
|
107
127
|
function delay(ms) {
|
|
@@ -126,4 +146,4 @@ async function retry(fn, options) {
|
|
|
126
146
|
// src/utils/sleep.ts
|
|
127
147
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
128
148
|
|
|
129
|
-
export { ChainId, DEAD_ADDRESS, NATIVE_ADDRESS, WETH9, allChainIds, allChainNames, chainNames, getChainFromName, getChainName, getWrappedNative, retry, sleep, toResult };
|
|
149
|
+
export { ChainId, DEAD_ADDRESS, NATIVE_ADDRESS, WETH9, allChainIds, allChainNames, chainNames, checkToApprove, getChainFromName, getChainName, getWrappedNative, retry, sleep, toResult };
|