@heyanon/sdk 1.0.1 → 1.0.2
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,16 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
import { TransactionParams, ChainId } from '../../blockchain';
|
|
3
|
+
import { FunctionOptions } from '../../adapter';
|
|
4
|
+
interface Props {
|
|
5
|
+
readonly args: {
|
|
6
|
+
readonly chainId: ChainId;
|
|
7
|
+
readonly account: Address;
|
|
8
|
+
readonly target: Address;
|
|
9
|
+
readonly spender: Address;
|
|
10
|
+
readonly amount: bigint;
|
|
11
|
+
};
|
|
12
|
+
readonly getProvider: FunctionOptions['getProvider'];
|
|
13
|
+
readonly transactions: TransactionParams[];
|
|
14
|
+
}
|
|
15
|
+
export declare function checkToApprove({ args, getProvider, transactions }: Props): Promise<void>;
|
|
16
|
+
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,26 @@ function getWrappedNative(chainId) {
|
|
|
104
105
|
}
|
|
105
106
|
return token;
|
|
106
107
|
}
|
|
108
|
+
async function checkToApprove({ args, getProvider, transactions }) {
|
|
109
|
+
const { chainId, account, target, spender, amount } = args;
|
|
110
|
+
const publicClient = getProvider(chainId);
|
|
111
|
+
const allowance = await publicClient.readContract({
|
|
112
|
+
address: target,
|
|
113
|
+
abi: viem.erc20Abi,
|
|
114
|
+
functionName: "allowance",
|
|
115
|
+
args: [account, spender]
|
|
116
|
+
});
|
|
117
|
+
if (allowance < amount) {
|
|
118
|
+
transactions.push({
|
|
119
|
+
target,
|
|
120
|
+
data: viem.encodeFunctionData({
|
|
121
|
+
abi: viem.erc20Abi,
|
|
122
|
+
functionName: "approve",
|
|
123
|
+
args: [spender, amount]
|
|
124
|
+
})
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
107
128
|
|
|
108
129
|
// src/utils/retry.ts
|
|
109
130
|
function delay(ms) {
|
|
@@ -135,6 +156,7 @@ exports.WETH9 = WETH9;
|
|
|
135
156
|
exports.allChainIds = allChainIds;
|
|
136
157
|
exports.allChainNames = allChainNames;
|
|
137
158
|
exports.chainNames = chainNames;
|
|
159
|
+
exports.checkToApprove = checkToApprove;
|
|
138
160
|
exports.getChainFromName = getChainFromName;
|
|
139
161
|
exports.getChainName = getChainName;
|
|
140
162
|
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,26 @@ function getWrappedNative(chainId) {
|
|
|
102
103
|
}
|
|
103
104
|
return token;
|
|
104
105
|
}
|
|
106
|
+
async function checkToApprove({ args, getProvider, transactions }) {
|
|
107
|
+
const { chainId, account, target, spender, amount } = args;
|
|
108
|
+
const publicClient = getProvider(chainId);
|
|
109
|
+
const allowance = await publicClient.readContract({
|
|
110
|
+
address: target,
|
|
111
|
+
abi: erc20Abi,
|
|
112
|
+
functionName: "allowance",
|
|
113
|
+
args: [account, spender]
|
|
114
|
+
});
|
|
115
|
+
if (allowance < amount) {
|
|
116
|
+
transactions.push({
|
|
117
|
+
target,
|
|
118
|
+
data: encodeFunctionData({
|
|
119
|
+
abi: erc20Abi,
|
|
120
|
+
functionName: "approve",
|
|
121
|
+
args: [spender, amount]
|
|
122
|
+
})
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
105
126
|
|
|
106
127
|
// src/utils/retry.ts
|
|
107
128
|
function delay(ms) {
|
|
@@ -126,4 +147,4 @@ async function retry(fn, options) {
|
|
|
126
147
|
// src/utils/sleep.ts
|
|
127
148
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
128
149
|
|
|
129
|
-
export { ChainId, DEAD_ADDRESS, NATIVE_ADDRESS, WETH9, allChainIds, allChainNames, chainNames, getChainFromName, getChainName, getWrappedNative, retry, sleep, toResult };
|
|
150
|
+
export { ChainId, DEAD_ADDRESS, NATIVE_ADDRESS, WETH9, allChainIds, allChainNames, chainNames, checkToApprove, getChainFromName, getChainName, getWrappedNative, retry, sleep, toResult };
|